I'm making a small client/server based game, on linux in c/c++ and I need to send the player turn to the server.

Here is my problem.

I want to send two integers to the server and sometimes it works perfectly, but sometimes the server receives both integer in the first recv() and its stuck.

I know that the best way is to package the messages.
The problem is I don't know how the syntax should look like.

**In theory--> the player input would be like an int column = 4 and a second int row = 1 and I package the message as 4|1 or something like this. Then I send from client to server and encode it on the server.
An example would be great or maybe some advice how stuff like this is handled probably.
I'm still very new to socket programming.**

Here is how my function looks like:

**Client:**

**#define BUFFER 512**

```
void send_turn_to_server(int sock, int row, int column)
{
   // sends  row to server from player turn

   char char_row[BUFFER];
   sprintf(char_row, "%d", row);
   char *message_from_client = char_row;
   int len, bytes_sent_row;
   len = strlen(message_from_client);

   if (sendall(sock, message_from_client, &len) == -1)
   {
      perror("sendall");
      printf("We only sent %d bytes because of the error!\n", len);
   }

   char char_column[BUFFER];
   int bytes_sent_column;
   //sends column from player turn
   //sprintf converts the int to char
   sprintf(char_column, "%d", column);
   char *column_from_client = char_column;
   len = strlen(column_from_client);

   if (sendall(sock, column_from_client, &len) == -1)
   {
      perror("sendall");
      printf("We only sent %d bytes because of the error!\n", len);
   }
   cout << "send_turn_to_server_complete" << endl;
}

```

Here I use a function from Beej's Guide to Network Programming, so I can be sure the whole buffer is sent.

**Client:**

```
int sendall(int s, char *buf, int *len)
{
   int total = 0;        // how many bytes we've sent
   int bytesleft = *len; // how many we have left to send
   int n;

   while (total < *len)
   {
      n = send(s, buf + total, bytesleft, 0);
      if (n == -1)
      {
         break;
      }
      total += n;
      bytesleft -= n;
   }

   *len = total; // return number actually sent here

   return n == -1 ? -1 : 0; // return -1 on failure, 0 on success
}

```

**Server:**

```
int receive_player_turn(int sock, int &int_row, int &int_column)
{
   int byte_count;
   char buf[BUFFER];
   byte_count = recv(sock, buf, sizeof buf, 0);
   cout << "The row from player: " << buf << endl;
   //The C library function int atoi(const char *str) converts the string argument str to an integer (type int).
   int_row = atoi(buf);
   //cleans the buffer
   bzero(buf, sizeof(buf));

   byte_count = recv(sock, buf, sizeof buf, 0);
   cout << buf << endl;
   cout << "The column from player: " << buf << endl;

   //converts the char string to an int
   int_column = atoi(buf);

   cout << endl

        << "receive player turn worked" << endl
        << "players turn was in the row " << int_row << " and in the column " << int_column + 1 << endl;

   return int_row, int_column;
}

```

**output correct from server:**

```
Player connected: SchleichsSalaticus
The row from player: 7
4
The column from player: 4

receive player turn worked
players turn was in the row 7 and in the column 5  
7 4

```

**output wrong from server:**

```
Player connected: SchleichsSalaticus
The row from player: 74

```