Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Answer: How can I make a client realize the server connection is gone?

( #73772=categorized answer: print w/ replies, xml ) Need Help??

Q&A > network programming > How can I make a client realize the server connection is gone? contributed by zigster

If the server closes the connection you should recieve an EOF on the socket. HOWEVER, tcp is designed to run over very slow and lossy networks, it is hard to tell the difference between a very slow/lossy network and a dead server.. In fact in tcp terms it is impossible. TCP works on a series of timeouts EVENTUALLY it will work out that the server is dead but it will take a long time.
Having said all that things to consider.
  • Write a ping method into your server, get it to send a datagram every n seconds. If the client does not recieve that datagram then you know the server is dead.
  • Look at the socket option SO_KEEPALIVE this will implement a ping protocol for you, however its timeouts are huge. 2 Hours or more, you can change this time out on a persystem basis (exactly how depends upon the system), you cannot do this AFAIK on a per connection basis.

For more information on this topic have a look at the UNIX Socket FAQ This document is as relivent to perl as it is to C, dont be put off by the fact that the examples are all in C. TCP is TCP is TCP.

Comment on Answer: How can I make a client realize the server connection is gone?
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2014-08-30 03:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls