tcp socket programming

Mohammed Smadi smadim2 at grads.ece.mcmaster.ca
Tue Oct 4 19:21:56 CEST 2005


hi;
If i have a tcp connection with a remote server, what is a good way to 
read all the data into a buffer before starting to process the data?
I know that the data recieved will be 3 lines with CRLF between them.  
However if I can sock.recv(1024) the output is not consistent all the 
time, sometime i get one line and sometimes i get two.  So I figures I 
should read all the data first then work on it and I used the following 
code:
result = []
while True:
    got=s.recv(1024)
    print got
    if not got: break
    result.append(got)
    got = [] # i tried also taking this out
s.close()

but this code just hangs in the loop and never quits

any ideas will be much appreciated

moe smadi




More information about the Python-list mailing list