Stupid Q: asyncore and disconnecting?

Kragen Sitaker kragen at dnaco.net
Thu Oct 5 01:22:59 EDT 2000


In article <20001004.192340.98221 at Jeremy.cerebralmaelstrom.com>,
Stephen Hansen <stephen at cerebralmaelstrom.com> wrote:
>Okay, I am using asyncore to make a little server, and am wondering how to
>go about detecting a client disconnected? When I 'telnet' into it, then
>close the connection, the server doesn't know its closed, each read/poll
>still receives just balnk data..... and, shouldn't it not try to read if
>there is nothing to be read?

A closed socket selects as readable, so you get handle_read_event();
but when you try to read it, the read returns 0.  I believe that that
is the only time read on a socket will ever return 0.  (When I tried
it, reading from a nonblocking socket that was open, but had no data
coming in, raised an exception.)
-- 
<kragen at pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Perilous to all of us are the devices of an art deeper than we ourselves
possess.
                -- Gandalf the Grey [J.R.R. Tolkien, "Lord of the Rings"]





More information about the Python-list mailing list