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.
abhishekpatelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

feenixCommented:
For TCP connections there is a timeout value, which controls when the connection is dropped. For example, if you have a timeout of 10 seconds and you remove the cable for more than that, the server gets a notice from the TCP/IP stack informing it about the disconnection.

So basically it's the same as if the client would have disconnected the connection 'gracefully'.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kejinCommented:
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.
0
abhishekpatelAuthor Commented:
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.
0
abhishekpatelAuthor Commented:
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.
0
feenixCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.