sockets: client dies...
Rick Lee
rwklee at home.com
Wed Jan 24 21:08:50 EST 2001
You should be able to tell on the recv(). It will throw an exception, not
just return "no data".
Here is from a piece of working code I have:
try:
data = self.connection.recv(MaxBytes)
except socket.error,v:
- Rick Lee
Keith Murphy wrote:
> actually, it's set to non-blocking.
>
> ::keith
>
> In article <94ksfl$r2a$1 at nntp6.u.washington.edu>,
> Donn Cave <donn at u.washington.edu> wrote:
> > Quoth Keith Murphy <kpmurphy at my-deja.com>:
> > | what can you do when the client dies in a client/server socket
> > | relationship? currently, my problem is that the server doesn't know
> > | when a client has terminated unexpectedly. is there any way to do
> so?
> >
> > Ideally, that will close the socket. If that happens, then the
> > socket becomes "readable" - that is, a recv() will return immediately
> > without blocking, returning '' (empty string.) (I'm assuming the
> > socket is blocking, per default.)
> >
> > I don't know any way to tell the difference between "closed" and "has
> > data", prior to calling recv(). But you can tell the difference
> between
> > readable and "would block" prior to recv(), with select().
> >
> > If the client dies and the socket doesn't close, then it may be worth
> > while to figure out why it doesn't.
> >
> > Donn Cave, donn at u.washington.edu
> >
>
> Sent via Deja.com
> http://www.deja.com/
More information about the Python-list
mailing list