Socket Disconnection

Andrae Muys amuys at shortech.com.au
Mon Jun 24 03:54:34 EDT 2002


"Colin Brown" <cbrown at metservice.com> wrote in message news:<3d16817e$1 at news.nz.asiaonline.net>...
> Hi Guyon
> 
> I assume here that you are talking TCP/IP.
> 
> If you are waiting on a receive [ data = connection.recv() ] then you will
> have an empty data string returned when the client disconnects.
> 
> If you are sending you will get an error telling you the link was shut down.
> 

Also note that the only reliable way to detect a client disconnect is
the latter.  If you want to demonstrate the failure of the recv()
approach, just yank out the ethernet cable on the client machine, and
notice that although the client is now disconnected, the server has no
idea.

Might I suggest taking a look at TCP/IP Illustrated Vol 1, by
W.Richard Stevens.  Definately a book to read if you are doing any
TCP/IP network programming.

Andrae Muys



More information about the Python-list mailing list