sockets: client dies...
Keith Murphy
kpmurphy at my-deja.com
Thu Jan 25 13:04:33 EST 2001
> Yes, frankly that's lame, but that's beside the point.
>
> Where you have
> data = ''
> data = string.strip(u.conn.recv(1024))
>
> Do this:
> data = u.conn.recv(1024)
> if not data:
> u.hold_funeral()
> data = string.strip(data)
>
> To reiterate: When the client dies, the connection will close.
> When the connection has closed, recv() will return an empty string,
> length == 0.
>
> Now, about that exception. There are hardly any good places to trap
> every possible exception, indiscriminately, and then just "pass" in
> the except block. This certainly ain't one of those places. Here's
> what I think I would do:
>
> try:
> data = u.conn.recv(1024)
> except socket.error, excval:
> if excval.errno == errno.EAGAIN:
> pass
> raise
>
> ... OK, I lied. I wouldn't do that. I really never want to set
> a socket nonblocking, and therefore I would never write that
> exception handler. Your code will execute more efficiently if you
> use select(), and then you won't need nonblocking either.
(Non-blocking
> does something for connect(), but that's a more advanced topic.)
>
> Donn Cave, donn at u.washington.edu
>
first of all, i'd like to thank mr cave, and everyone for their help
thus far.
if i don't setblocking to 0, then it will get hung up on one client...
waiting for a message, right? i'm afraid i don't know what select()
is...
i guess what i'd like is a better way to sit around and listen to n
hosts, and be able to detect when one has died.
much thanks again,
::keith
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list