size of socket.recv buffer

Joshua Muskovitz joshm at
Mon Feb 25 22:36:22 EST 2002

No, what he's saying is that the sender and the receiver operate
independently.  Think of the socket connection as a hose from the sender to
you, ending in a huge bucket.  You aren't allowed to carry the huge bucket
back to your own code, it is attached to the hose.  Instead, you have to use
your own bucket to scoop stuff out of the huge one, and then carry it off.
The value you pass to recv() is the size of your own bucket.  When you call
recv(), you are going to the huge bucket, scooping out as much as is in
there (up to the size of your own bucket), and going back to your own
program.  If you didn't get all that you needed in that one trip, you have
to go back.

The other half of it is that the sender of the stuff is pushing it through
the hose at its own pace.  If it is very busy doing other things, it might
not put the stuff through the hose very quickly.  So you might get to the
huge bucket looking for stuff, but there isn't very much stuff there.  So
you get what is there, and return.  It might not even be enough to fill your
own bucket.  (There might not even be anything for you on a given trip to
the big bucket.)

So the purpose of sending you the octet count (and I believe that octet ==
byte) is so that you'll know whether to expect more stuff to come out of the
hose or not.  You have to keep track of how much stuff you've gotten so far,
to know whether you have to go back and get more.  You handle this by
calling len() on the returned string, to see how much stuff actually got
scooped into your bucket.  You keep a running total of how much you've

Does that help?

# Joshua Muskovitz
# joshm at
def lyyrs(sig): return '-'.join(sig.split()+["ly y'rs"])
lyyrs('Hire me!  I need the work!')

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

More information about the Python-list mailing list