Question

In my recent project, I need to use the UDP protocol to transmit data. If I send data by using size = s.sendto(data, (<addr>, <port>)), will the UDP protocol ensure that the data is packed into one UDP packet? If so, will size == len(data) always be True? Is there anything that I misunderstood?

More precisely, will 'sendto()' split my data into several smaller chunks and then pack each chunk into UDP packet to transimit?

Was it helpful?

Solution 2

Finally, I got the answer from "UNIX Network Programming", Chapter 2.11 Buffer Sizes and Limitations, Section UDP Output.

Steps and buffers involved when an application writes to a UDP socket.

This time, we show the socket send buffer as a dashed box because it doesn't really exist. A UDP socket has a send buffer size (which we can change with the SO_SNDBUF socket option, Section 7.5), but this is simply an upper limit on the maximum-sized UDP datagram that can be written to the socket. If an application writes a datagram larger than the socket send buffer size, EMSGSIZE is returned.

OTHER TIPS

The length of UDP packet is limited. If your data is too large, the return value can't equal the length.There are also some situations, such as not enough send buffer, network fault. The size only means the bytes that have been sent to send buffer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top