I have a client application using winsock’s sendto() method to send data to a server application with UDP. On my client application I make, say, 5 quick sendto(). On my server application, I wait for, say, 10 secs, and then do a select() and recvfrom(). Will the recvfrom() give me the first packet sent by the client or will it be an arbitrary one (whichever one arrived first)? Will I still be able to get the other 4 data packets or does winsock’s UDP framework only buffer one?
I have a client application using winsock’s sendto() method to send data to a
Share
UDP gives no guarantee to the received ordering of packets, so basically, the first packet you
recvfrom()might be the first packet you sent, but must not be – that’s what TCP is for (which guarantees ordering of received data). You might not receive a part of the packets (or any, for that matter) at all if they were lost in transit.For the second part: generally, the operating system will buffer a certain amount of packets for you, this depends on the socket buffer set up for UDP sockets – the buffer is specific to every socket, and not shared between them. On Windows, I’m not sure at how to get at the size of the buffer, on Linux, check out “/proc/sys/net/ipv4/udp_mem”; generally, you’ll easily fit five UDP packets in there.