Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

udp

sendto

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?

like image 327
YON Avatar asked Jul 10 '26 10:07

YON


1 Answers

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.

like image 163
wangsquirrel Avatar answered Jul 13 '26 17:07

wangsquirrel