Python sockets/select

Donn Cave donn at oz.net
Wed Jun 21 01:49:18 EDT 2000


Quoth "David Allen" <s2mdalle at titan.vcu.edu>:
...
| When I select() sockets for reading, writing, and error conditions,
| there are sockets (usually connected to clients who have already
| quit or died unexpectedly) that don't show up in the error queue,
| but continually flag select() as being readable.  When I read them,
| of course, '' comes back.
|
| For some reason, sometimes '' comes in for valid clients, so I 
| can't just disconnect a client because I get that from them.  Is
| there a way to detect which clients are alive and which aren't?
| What causes a client to send '' when I didn't tell it to, according
| to select()?  (The clients are also written in python)

When you get 0 bytes back from a read, that's EOF (End Of File.)
As you apparently surmised.  That is indeed a readable event, at
least the first time.  I'd say behavior after the first 0 byte
read is probably undefined, but anyway it's not going to do anyone
any good.

You should never get a 0 byte read before the socket has been
closed on the other end, so it sounds like there's something
wrong (in your server, not in your clients.)

	Donn Cave, donn at oz.net



More information about the Python-list mailing list