Buffer size when receiving data through a socket?
John Salerno
johnjsal at NOSPAMgmail.com
Tue Jun 17 09:39:07 EDT 2008
"John Salerno" <johnjsal at NOSPAMgmail.com> wrote in message
news:20080616202135.41c407de.johnjsal at NOSPAMgmail.com...
> from socket import *
>
> host = 'localhost'
> port = 51567
> address = (host, port)
> buffer_size = 1024
>
> client_socket = socket(AF_INET, SOCK_STREAM)
> client_socket.connect(address)
>
> 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?
It runs fine without the if statement, but I'm wondering if I just haven't
encountered the proper problem situation yet.
More information about the Python-list
mailing list