SocketServer class - basis problem

Peter Hansen peter at engcorp.com
Tue Jun 24 15:42:53 CEST 2003


Miki Tebeka wrote:
> 
> Hello, Leonard,
> 
> > data = s.recv(1024)
> > s.close()
> > print 'Received', data
> >
> > Why does s.recv() hang the client?  It seems like server is not
> > handing back "blah", but I'm sure it is.....

> I think that the socket buffer is  not full (since you are waiting for
> 1024 and "blah" is not enough).

This is not how the size parameter to recv() is used.  It is a
*maximum*, meaning any amount of data from zero bytes (if the 
socket is closed) to that value will be returned, with *no*
guarantees how much is actually returned.  Often, but absolutely
not always, you will get a whole "line" and newbies will be
deceived into thinking it's enough just to recv(1024) and 
carry on, but eventually such code will fail.

-Peter




More information about the Python-list mailing list