Hello, Shen!

On Wed, 27 May 1998, Shen Hui wrote:

>  I want to write a server program. Several clients can
>connect to it at the same time(using socket() ,SOCKET_STREAM
>and SOCKET_DGRAM).
>
>  Now here is a problem. If some clients abort abmormally,
>for example, by press
>"^C" or killed by user, clients can not tell the server to
>reclaim those sockets. In this circumstance, I want the
>server know this and then close those sockets that do not
>connect with the clients any more. 
>
>  How can I know the status of the sockets such as "weather
>they are connected or broken" ?

1. When writing client program, it is nice to write signal handlers,
   that will correctly close the socket.

2. Kernel should close all sockets, that program used, after i was
   stopped. So, on IP level, socket should closed anyway. In case
   socket was closed, server side will get End Of File mark, when
   trying to read from socket. Anyway, if you use blocking IO and
   waiting for data without checking the connection, there can
   happen network problems, so server will freeze.

3. You can use KEEP-ALIVES to check the connection is OK. ( alarm()
   is perfect for this ). Just send some keepalive packets with
   predefined intervals, or expect them from client side. In first case
   if connection get broken, you'll got some error on socket, in second
   case, you can just close() the socket if you get no keepalive.

Bye.
--
The SAME WAVE keeps coming in and COLLAPSING like a rayon MUU-MUU ...

--
    With best of best regards, Pawel S. Veselov (aka Black Angel)
                   Internet e-mail : [EMAIL PROTECTED]
    Web page : http://www.druid.ml.org/~vps/ | ICQ UIN : 5252265

Reply via email to