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

Philipp Hagemeister phihag at phihag.de
Tue Jan 8 07:42:07 EST 2013


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 ?
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20130108/23292360/attachment.sig>


More information about the Python-list mailing list