Could somebody please explain to me general contract of python's socket.send() method? I am making some kind of a traffic generator as a part of an educational project.
I do simple logging whenever socket.send() method executes, i send some traffic and write down to file the time when the method finished ( among other things i log). These logs show that i sent more messages then the wireshark shows, this happens when my outgoing traffic gets relatively high.
I have read: https://docs.python.org/2/howto/sockets.html#socket-howto
As mentioned in the link i provided: ' They do not necessarily handle all the bytes you hand them (or expect from them), because their major focus is handling the network buffers. In general, they return when the associated network buffers have been filled (send)'.
If i understod correctly, there is no guarantee that my message will acctualy be sent. I can read how many bytes socket.send() handled , but i would like to know what excatly does it mean by 'handled'.
Can somebody explain to me:
When you are using TCP, the network layer does guarantee that all the bytes you pass to send()
will actually be sent (if not, the socket will be closed). However, it sounds like you are counting packets rather than bytes.
There is not always a relationship between the number of times you call send()
and the number of packets that are sent. The network layer is free to consolidate or split the data you pass to send()
into differently sized packets, as long as it all finds its way to the remote end in the same order it was sent.
If you want more control over the number of packets that are sent, use UDP instead of TCP.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.