Re: what’s the difference between socket.send() and socket.sendall() ?

Discussion in 'Python' started by Philipp Hagemeister, Jan 8, 2013.

  1. socket.socket.send is a low-level method and basically just the
    C/syscall method send(3) / send(2). It can send less bytes than you
    requested.

    socket.socket.sendall is a high-level Python-only method that sends the
    entire buffer you pass or throws an exception. It does that by calling
    send until everything has been sent or an error occurs.

    If you're using TCP with blocking sockets and don't want to be bothered
    by internals (this is the case for most simple network applications),
    use sendall.

    Otherwise, use send and make sure to read and process its return value.

    - Philipp

    On 01/07/2013 11:35 AM, iMath wrote:
    > what’s the difference between socket.send() and socket.sendall() ?
    >
    > It is so hard for me to tell the difference between them from the python doc
    >
    > so what is the difference between them ?
    >
    > and each one is suitable for which case ?
    >



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

    iEYEAREKAAYFAlDsFCEACgkQ9eq1gvr7CFyqswCgmgHImzhVDS7mlBrAKs12wD3F
    z6gAoKPxDxEy1GoVNAEQVlcbpxL6dqzs
    =Rpq5
    -----END PGP SIGNATURE-----
    Philipp Hagemeister, Jan 8, 2013
    #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. Tim Black
    Replies:
    1
    Views:
    1,065
    Alan Kennedy
    Aug 3, 2004
  2. Irmen de Jong
    Replies:
    0
    Views:
    322
    Irmen de Jong
    Jan 8, 2005
  3. Robert Brewer
    Replies:
    4
    Views:
    3,657
    Irmen de Jong
    Jan 16, 2005
  4. Thomas Rachel
    Replies:
    0
    Views:
    183
    Thomas Rachel
    Jan 7, 2013
  5. Steven D'Aprano
    Replies:
    1
    Views:
    106
    Chris Angelico
    Jan 7, 2013
Loading...

Share This Page