I would like to obtain a behavior similar to this:
The recv()
and send()
functions do not guarantee to send/recv all data (see man recv, man send)
You need to implement your own send_all()
and recv_all()
, something like
bool send_all(int socket, void *buffer, size_t length)
{
char *ptr = (char*) buffer;
while (length > 0)
{
int i = send(socket, ptr, length);
if (i < 1) return false;
ptr += i;
length -= i;
}
return true;
}
The following guide may help you Beej's Guide to Network Programming