sendto and recvfrom keep grouping packets together??
-
Hi, For some reason, if I call multiple sendto's, like this: sendto(sock, etc etc); sendto(sock, etc etc); sendto(sock, etc etc); Then I have a recvfrom loop threaded on my client side, the recvfrom will often receive all the data from multiple sendto's in one 'big' packet and stuff it all together so I can't parse it correctly. What the hell?? Isn't it possible to send a number of TCP packets right after each other and have them received separately?? Thanks! Kelly Ryan
-
Hi, For some reason, if I call multiple sendto's, like this: sendto(sock, etc etc); sendto(sock, etc etc); sendto(sock, etc etc); Then I have a recvfrom loop threaded on my client side, the recvfrom will often receive all the data from multiple sendto's in one 'big' packet and stuff it all together so I can't parse it correctly. What the hell?? Isn't it possible to send a number of TCP packets right after each other and have them received separately?? Thanks! Kelly Ryan
No, because TCP is a streaming protocol. Because TCP is reliable (in-order and reliable), you can however wait until you have read a certain number of bytes and then assume that is one 'packet'. For fixed size packets this means you end up with something like read( packet, sizeof(Packet) ) read( packet, sizeof(Packet) ) And for variable size packets: read( packetsize, sizeof(long) ) read( packet, packetsize) read( packetsize, sizeof(long) ) read( packet, packetsize) As an aside, ::send() and ::sendto() are generally used for UDP, whilst TCP normally only uses ::send()
-
No, because TCP is a streaming protocol. Because TCP is reliable (in-order and reliable), you can however wait until you have read a certain number of bytes and then assume that is one 'packet'. For fixed size packets this means you end up with something like read( packet, sizeof(Packet) ) read( packet, sizeof(Packet) ) And for variable size packets: read( packetsize, sizeof(long) ) read( packet, packetsize) read( packetsize, sizeof(long) ) read( packet, packetsize) As an aside, ::send() and ::sendto() are generally used for UDP, whilst TCP normally only uses ::send()