newbie question

Krzysztof Stachlewski stach at fr.USUN.pl
Thu Apr 15 17:45:47 EDT 2004


jeff wrote:

> ok this is the bit i'm working with, i'm tinkering with sockets.
> when the recieved text == kill, i want the socket to close.  actually, the 
> example i posted worked for me too, but i don't understand why this 
> doesn't.
> 
> while 1:
> 	sdata = s.recv(1024)
> 	if not sdata: break
> 	if sdata == "kill": s.close()
> 	print "Recieved:", sdata

First of all, you can't be sure that you will receive the text "kill"
in one piece. It could happen that one recv() call will give only
"ki" and the following recv() will return the rest of it.
Moreover - try to print repr(sdata) and see what *exactly* is received.

-- 
Stach  Tlen: stachobywatelpl, GG: 1811474
        Jabber: stach at jabber atman pl



More information about the Python-list mailing list