Link to home
Start Free TrialLog in
Avatar of abhishekpatel
abhishekpatel

asked on

linux network programming

if there is a client is connected to the server and if we remove
the cabel connecting them then how server comes to know
that at the other side client is not present.
ASKER CERTIFIED SOLUTION
Avatar of feenix
feenix
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kejin
kejin

This would hardly be an useful solition. First, the tcp engine wouldn't start tcp timer for that connection if there is no outstanding package on it for ACK. So, if the cable was removed when the connection is in fully idle state, the server wouldn't find it even if you set the tcp timeout to 10 seconds or shorter.

Second, even if the cable was removed during non-idle state, setting tcp timeout to 10 seconds is questionable. The default tcp timeout for most tcp engine is 9 to 2 minutes (i.e 540 to 120 seconds). Setting this timer to as short as 10 seconds would cause tcp connection be pre-maturelly removed for some transient errors.  

Setting TCP_KEEPALIVE on may allow server to detact the cable failure of a completely idled connection via a low level ping. However, the keep alive timer by default is 2 hours and not all systems allow you to change it without reconfigure the kernel. An application level ping may be used alternatively but it can only find the cable failure till next ping time and has to wait for the long enough tcp timeout (i.e. 120 to 540 seconds) before report the error.
Avatar of abhishekpatel

ASKER

how i programmed(programing in c under linux) my server so it can comes to know that on the other side client is not present in the fully idle connection.
           basicly my server must come to know when the client
is logged in or logged out. If there is a network failure occures
in betwween them then also the server must know that network
failure and logged out the client so its total login time can be
calculated exactly.
i want my server to know the disconnection ofclient indirectly (e.g. cable break,network failure). I don't want the system telling to my server that client is not present
at the other side.
For kejin, I didn't say that you SHOULD set the timeout to that short value, I only used the 10 seconds as an example value. Of course the reasonable values are a lot longer.

And you are right for the fact that if there is no data to be sent (or just sent but waiting for an ACK), the server does not disconnect. That I forgot to mention.