How to detect when socket connection closes?

How to detect when socket connection closes?

Post by Tessa L » Fri, 07 Jul 1995 04:00:00



I'm writing a server which serves multiple clients connected to it via
sockets.  Basically the server keeps a list of open sockets, and
periodically it'll write() a message on all the sockets in the list.  If a
client crashes or otherwise closes the connection, my server would like to
know about it so that it can remove that socket descriptor from its list of
open sockets.  How can the server query the state of a soocket?

What I'm doing now is calling select(&read_fds, &write_fds, &except_fds,
&timeval) and examining the value of write_fds.  After one chunk is written
to a broken connection, select determines that another write will block and
so that fd is removed from write_fds.  I don't think this is the way I'm
supposed to do it.

When will an exception ever be raised on a socket?  Is that what I'm
looking for?  The description in Unix Network Programming didn't clarify
what exactly could cause an exception.

Thanks in advance, any suggestions appreciated.

Tessa Lau

 
 
 

How to detect when socket connection closes?

Post by James R. R. Servic » Thu, 13 Jul 1995 04:00:00



>[...] I'm writing a server which serves multiple clients connected to it via
>sockets.  Basically the server keeps a list of open sockets, and
>periodically it'll write() a message on all the sockets in the list.  If a
>client crashes or otherwise closes the connection, my server would like to
>know about it so that it can remove that socket descriptor from its list of
>open sockets.  How can the server query the state of a soocket?
>What I'm doing now is calling select(&read_fds, &write_fds, &except_fds,
>&timeval) and examining the value of write_fds.  After one chunk is written
>to a broken connection, select determines that another write will block and
>so that fd is removed from write_fds.  I don't think this is the way I'm
>supposed to do it.

When select() says one of the read_fds are ready but you only can read 0 bytes
from it then the other end has closed the connection.

--


800 Kipling Ave. - Room KR132       FAX:   (416) 207-6384
Toronto, Ontario, CANADA  M8Z 5S4   voice: (416) 207-6946

 
 
 

1. Closing sockets and closing connections

Is there anway (not the reset button :-) kill a TCP connection
immediatly?

Im writing a TCP/IP server, but if I only close the socket I can't
restart within
1,5-2 minutes (cause the Java-Applet-client does not close) and binding
(bind()) fails. e.g. Apachie could restart immediatly. I've tried
serveral things (shutdown(fd,0) before close(fd); SO_REUSEADDR etc.
Nothing is working.

is there any sollutions?

2. SMC Ultra32 EISA Supported?

3. Detecting socket closed by firewall

4. UltraEdit in Linux?

5. detecting a socket close on the other side

6. HELP: XGetGeometry vs XMapWindow

7. Detect the socket been closed..

8. Changing the Default Route for PPP??

9. Detecting streams socket closed??

10. detecting when the other end of a socket is close'd

11. detecting closing sockets

12. detecting inetd client has closed socket

13. Detecting close on sockets