socket question
Chris Liechti
cliechti at gmx.net
Sun Jan 20 15:06:21 EST 2002
"maximilianscherr" <MaximilianScherr at T-Online.de> wrote in
news:mailman.1011552989.3398.python-list at python.org:
> have seen it, but don't really understand it, like if i do a
> socket.recv() does it wait until it receives data?
normally sockets are blocking so yes it waits for data. the socket can be
changed to non-blocking in that case it returns immediately an empty
string. not that recv(n) does receive up to n characheters. receiving is
therefore done in a loop. its also common to receive until a special
character/prompt is received.
note that the same applies to send. in python 2.2 there is sendall which
sends everything, with send it returns the truely sent characters. i use:
s = "messy"
while len(s):
s = s[conn.send(s):]
there is also makefile. that way you can send and receive like its
stdin/stdout or any other file (write, read). however i never used this.
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list