If you are sending via tcp then theres no prob of packets being out of order / lost, so your recv func wants to look something like this and the send similar.
Every message that you send attach a header like aluser suggested.
Code:
//read in the header which will give you the total size of the message
//...........
//is there more to receive or was the header the only thing?
if( p_header->size > sizeof(Msg_header) )
{
int remaining = p_header->size - bytes_recv;//whats the bytes remaining
while(remaining != 0)//loop until we get all the data
{
//cast required for winblows
this_recv = recv(m_socket,reinterpret_cast<char*>(buf + bytes_recv),remaining,0);
if(this_recv <= 0)//there was an error
{
//this could be would block determine if we carry on
//.........
//if we are not carrying on return an error
return this_recv;
}
else
{
remaining -= this_recv;
bytes_recv += this_recv;
}
}
}
return bytes_recv;
this just loops until you get the correct amount of bytes or there was an error which means you want to exit ie. connection reset.