newbie question
Chris Green
cmg at dok.org
Fri Apr 16 18:12:40 EDT 2004
jeff <plastic"no-spam-pls"@xsintrk.net> writes:
> how can i be sure i have received the entire string?
You need to queue up the data returned and have a protocol defined for
when a command terminates such as '\r\n'. Ugly Untested code below.
buf = ""
delim = "\r\n"
while 1:
sdata = s.recv(1024)
if not sdata:
break
# append sdata to the buf
buf += sdata
while 1:
idx = buf.find(delim)
if idx > -1:
cmd = buf[:idx] # grab cmd
buf = buf[:idx + len(delim)] # save off the rest of the command
if cmd == "kill":
s.close()
print "Received:", sdata
else:
break # breaks inner loop
--
Chris Green <cmg at dok.org>
TCP: Treason uncloaked!
More information about the Python-list
mailing list