Q: How to save the results from a socket

Paul Everitt (paul@cminds.com)
Mon, 18 Jul 1994 08:36:09 -0400 (EDT)

I have been learning the socket stuff, and have had some luck with code
that gets stuff from a remote host, and assigs the resulting string to a
variable. However, the following buffered-read code doesn't work:

def GET(host, port, string):
s = socket(AF_INET, SOCK_STREAM)
s.connect(host, port)
s.send(string + '\n')
totalbuf=''
while 1:
buf = s.recv(1024)
len(buf)
totalbuf=totalbuf+buf
if not buf: break
b=sys.stdout.write(buf)
len(b)
sys.stdout.flush()
return totalbuf

I've tried a thousand permutations, but it seems that s.recv(1024) is not
returning a string during the while loop (is it an fd?). I want to store
the results to process later, rather than write to stdout.

Thanks for any help.

Paul Everitt V 703.785.7384 Email Paul.Everitt@cminds.com
Connecting Minds, Inc. F 703.785.7385 WWW http://www.cminds.com/