Search code examples
pythonudpsendto

Python - Is sendto()'s return value useless?


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?


Solution

  • 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.