size of socket.recv buffer

Tim Peters tim.one at comcast.net
Tue Feb 26 01:43:07 EST 2002


[Locke]
> The argument to recv is supposed to be the buffer, acording to the
> documentation.

Certainly not according to Python's docs.  It's the maximum length of the
string you want Python's recv to return.

> But the doc doesnt say: buffer measured in what?

Python's recv() returns a string; it's an upper bound on

    len(sock.recv())

> Is it bytes?  Octets?  (by the way, what is the diff between a byte
> and an octet?)

Nothing in real life <wink>.

> See, I am writing a pop3 client type thing, after requesting a
> message from the server, my first s.recv tells me how long the
> message will be in octets.  So then I call s.recv again passing the
> number of octets as the argument to s.recv. Shouldn't this download
> the entire message? What actually happens is that it cuts off
> right in the middle of the message.
> ...

This is what you need:

    http://py-howto.sourceforge.net/sockets/sockets.html

Read that and it will be clearer.  Note that you can't even count on your
*first* recv to tell you the number of octets in one gulp, although that's
quite likely to work most of the time.  Sockets are a low-level facility, as
the title of the Python doc section hints:

    7.2 socket -- Low-level networking interface





More information about the Python-list mailing list