Buffer size when receiving data through a socket?

MRAB google at mrabarnett.plus.com
Wed Jun 18 07:16:18 EDT 2008


On Jun 18, 7:52 am, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> On Tue, 17 Jun 2008 09:39:07 -0400, "John Salerno"
> <johnj... at NOSPAMgmail.com> declaimed the following in comp.lang.python:
>
>
>
> > > while True:
> > >    data = raw_input('> ')
> > >    if not data:
> > >        break
> > >    client_socket.send(data)
> > >    data = client_socket.recv(buffer_size)
> > >    if not data:
> > >        break
> > >    print data
>
> > > client_socket.close()
>
> > Also, is that second "if not data: break" statement necessary? It seems like
> > once you get past the first if, you don't need the second one. Of course, I
> > guses it's possible that the server could return a False value, but even
> > still, would it make sense to break out of the loop and close the connection
> > because of that?
>
>         The first if is checking for lack of interactive input -- and, as
> coded, will never break out as ANY response to the > prompt will have a
> newline attached.
>
[snip]
FYI, I've just checked:

>>> raw_input('> ')
> abc
'abc'

raw_input() doesn't put a newline on the end.



More information about the Python-list mailing list