Hi,
I wondered what are the implications of setting keepalive to true.
can I detect, say, from a server, that a client crashed? and if so,
how?
You should be more specific about what exactly you're talking about.
Based on the limited information, I'm going to make the assumption that
you want to set the SO_KEEPALIVE option for a network socket in .NET.
If so, then you should look at the Socket.SetSocketOption() method, and
the SocketOptionName.KeepAlive enumeration value.
Using the KeepAlive option can help you detect a client that's crashed.
However, the default settings will only cause keep-alive packets to be
sent every 2 hours. This may or may not be a frequent-enough interval
for your purposes.
I would generally discourage the use of any sort of "keep-alive" type
functionality. It has its uses, but it is much more common that the
server should not care at all about whether the client is reachable at a
specific point in time, if the server would not otherwise need to
communicate with the client.
If you want a timeout on the protocol, you should simply define that and
implement it. For example, say that if the client has no activity for
more than one hour, the client will simply be dropped and will have to
reconnect if it wants to use the server again.
The big problem with using a "keep-alive" is that it can actually create
connection errors when none would normally have happened. If it's okay
for a client to remain connected for hours or days or whatever without
any actual activity, then just let it be connected for that long.
Otherwise, if you try to communicate with the client, you could find
that you just happen to try to send data to the client during some brief
period of time that the actual communications path was interrupted. In
that case, you wind up detecting a broken connection, creating an error
when in fact if you'd just waited a few moments, the connection might be
okay.
As an example: suppose you've got a client computer that needs to be
moved from one side of the room to the other, requiring the network
cable to be disconnected and reconnected elsewhere. Suppose you happen
to send your "keep alive" at the moment the person was moving it. When
the person plugs the computer in again, all of the sudden they will find
that the server has disconnected them, for no really good reason.
If you are concerned about idle clients using server resources, then
again the right technique is to monitor those resources and define some
policy under which you will disconnect idle clients (on a
least-recently-used basis, for example).
If that's not what you're asking about, you'll need to clarify.
Pete