Async sockets recv 01-17-2014, 07:56 PM
#1
I'm using winsock 2 async sockets. Because I've read on MSDN that using send() will not always send all the bytes so I've wrote a function to ensure all the bytes are send
My packets are serialized and end with a '\r\n'. But I'm thinking about this scenario:
1 ) The server is trying to send me a packet, but it fails to send all the data at once and send it via 2 send() commands;
2 ) The client (async socket) is receiving the first packet but will it contain all the data, or the packets will arive as 2 (because 2 send()'s are used)
And if the packets will arrive as 2 packets, can someone give me an example how to append the two packets (having in mind that I'm using async sockets). Now my code for receiving packets is:
Any suggestions ?
Code:
int bufsize = strlen(sendstring);
int offset = 0;
int r; //Counting the sended bytes
while (offset < bufsize) {
r = send(sock, sendstring+offset, bufsize-offset, 0);
if(r <= 0) break; //SOCKET_ERROR or other errors
if(WSAGetLastError() == WSAENETRESET || WSAECONNABORTED || WSAENETUNREACH || WSAECONNRESET || WSAENETDOWN) return 0;
offset += r;
}My packets are serialized and end with a '\r\n'. But I'm thinking about this scenario:
1 ) The server is trying to send me a packet, but it fails to send all the data at once and send it via 2 send() commands;
2 ) The client (async socket) is receiving the first packet but will it contain all the data, or the packets will arive as 2 (because 2 send()'s are used)
And if the packets will arrive as 2 packets, can someone give me an example how to append the two packets (having in mind that I'm using async sockets). Now my code for receiving packets is:
Code:
case FD_READ: {
CreateThread(NULL, 0, HandleRecv,(LPVOID)wParam, 0, &thread);
}Any suggestions ?


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)