I have two ideas for you:
- Use XML for the protocol. This way you know exactly when each message ends.
- Send the packet size in the header of each "packet", so you know how much to read from the socket for this particular packet.
Edit: Look at this dummy code for (2)
int buffer_size;
char* buffer;
read( socket, &buffer_size, sizeof(buffer_size));
buffer = (char*) malloc(packet_size);
read( socket, buffer, buffer_size );
free( buffer) ;
EDIT:
, , "read()", "read()" ing, .
, . XML. , XML parlty, XML, , , 0 "" .