Re: sending very large packets over the network

Discussion in 'Python' started by Thomas Jollans, Aug 2, 2007.

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

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQBGsRz/JpinDvQhQ0sRAjetAJsH1+SOQse4DYhI1yKCAU+fPdr0zgCgkZ4J
    4/7IOir7Tcbcun3u//QiFWg=
    =o/lb
    -----END PGP SIGNATURE-----
     
    Thomas Jollans, Aug 2, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sreehari
    Replies:
    7
    Views:
    370
  2. Ashoka!
    Replies:
    6
    Views:
    579
    Ashoka!
    Apr 26, 2007
  3. Gary Herron
    Replies:
    1
    Views:
    459
    Azazello
    Aug 2, 2007
  4. Krzysztof Retel

    Network packets processor advice

    Krzysztof Retel, Feb 9, 2009, in forum: Python
    Replies:
    0
    Views:
    291
    Krzysztof Retel
    Feb 9, 2009
  5. Zsdfhdfgasdf Gsfgsdgsdgsd

    Sending packets over TCP server

    Zsdfhdfgasdf Gsfgsdgsdgsd, Jul 15, 2010, in forum: Ruby
    Replies:
    6
    Views:
    371
    Zsdfhdfgasdf Gsfgsdgsdgsd
    Jul 15, 2010
Loading...

Share This Page