sending very large packets over the network

Thomas Jollans thomas at jollans.com
Wed Aug 1 19:53:30 EDT 2007


On Thursday 02 August 2007, Walker Lindley wrote:
> OK, I'm back with another networking question. I'm trying to seend large
> amounts of information over TCP (the length of data being given to send()
> is on the order of 16000 characters in length). Unfortunately on the
> receiving end, the packets appear to be truncated. So I wrote some code
> that continuously tries to send bigger and bigger packets until it fails
> and noticed that it never fails at the same length. I'm not even sure these
> two things are related, but is there some undocumented (or documented and I
> missed it) maximum size for data you can pass to send()?

First off, very long messages, that is messages whose length cannot be 
represented in a C size_t, are probably right out ;-)

from the send(2) manual page on my Debian system:

> If the message is too long to pass atomically  through  the  underlying
> protocol, the error EMSGSIZE is returned, and the message is not trans‐
> mitted.


from the Python socket.send documentation [1]
> Send data to the socket. The socket must be connected to a remote socket.
> The optional flags argument has the same meaning as for recv() above.
> Returns the number of bytes sent. Applications are responsible for checking
> that all data has been sent; if only some of the data was transmitted, the
> application needs to attempt delivery of the remaining data.

that makes it quite clear that it's possible that not all data was 
transmitted. That you were unable to find a fixed size may be explainable in 
many ways - it might just be the way your operating system's TCP/IP stack 
works.

If you just want to send data in some way or another, do yourself a favour and 
use socket.sendall instead of socket.send. Docs for socket.sendall: [1]

> Send data to the socket. The socket must be connected to a remote socket.
> The optional flags argument has the same meaning as for recv() above.
> Unlike send(), this method continues to send data from string until either
> all data has been sent or an error occurs. None is returned on success. On
> error, an exception is raised, and there is no way to determine how much
> data, if any, was successfully sent.


[1]: http://docs.python.org/lib/socket-objects.html

-- 
      Regards,                       Thomas Jollans
GPG key: 0xF421434B may be found on various keyservers, eg pgp.mit.edu
Hacker key <http://hackerkey.com/>:
v4sw6+8Yhw4/5ln3pr5Ock2ma2u7Lw2Nl7Di2e2t3/4TMb6HOPTen5/6g5OPa1XsMr9p-7/-6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/python-list/attachments/20070802/5a5550bc/attachment.sig>


More information about the Python-list mailing list