implementing keepalives with Java

Posted by Bilal on Stack Overflow See other posts from Stack Overflow or by Bilal
Published on 2010-12-30T16:43:05Z Indexed on 2010/12/30 16:53 UTC
Read the original article Hit count: 208

Filed under:
|
|

Hi All,

I am biulding a client-server application where I have to implement a keepalive mechanism in order to detect that the client has crashed or not. I have separate threads on both client and server side. the client thread sends a "ping" then sleeps for 3 seconds, while the server reads the BufferedInput Stream and checks whether ping is received, if so it makes the ping counter eqauls zero, else it increments the counter by +1, the server thread then sleeps for 3 seconds, if the ping counter reaches 3, it daclares the client as dead.

The problem is that when the server reads the input stream, its a blocking call, and it blocks untill the next ping is received, irrespective of how delayed it is, so the server never detects a missed ping.

any suggestions, so that I can read the current value of the stream and it doesn't block if there is nothing on the incoming stream.

Thanks,

© Stack Overflow or respective owner

Related posts about java

Related posts about inputstream