On Wed, 27 May 1998, Shen Hui wrote:
> Hi, everyone,
>
> 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" ?
>
> Thanks in advance.
>
For press ctrl-C is better to intercept the signal to do a
"civilizated shutdown" for client. It is't just socket but also should be
databases or files opened.
If program is killed with -9 you can't do this. A solution is to use
socket with SO_KEEPALIVE (man getsockopt) and this option should signal you
the socket have trouble. This option work just for tcp.
For udp, one socket can talk with more than one client. So you must
manage that something diferent. I think is't necesary to close the
udp socket but you might delete data structures keeping clients information.
But I thing you must manage (something like keepalive) yourself
(depending by your program).
------------------------------------------------------------------------------
Best wishes,
Marcel - Titus MARGINEAN
[EMAIL PROTECTED], [EMAIL PROTECTED]