Hello. I am curious how to monitor a socket connection? Meaning, Lets say I have successfully made a connection, and for the period of my application, I need to monitor that connection. If the connection is lost, I have a list of conditionals to execute and same if the socket is remained open. So, I guess this is both a Threading and Socket Question, but I am totally lost on how to go about doing this. I would greatly appreciate any help possible.
Hi Rick! I was working with this problem more than one year. At my job we were migrating some GSM staff to TCP/IP network. And finally we concluded that the bestest way to monitor the connection is to send "heartbeats" each other. Heartbeat is just 2 bytes message: 1st byte is header ("I am heartbeat") and second any value you agreed in you connection protocol. Server sends to client, client sends to server. Lets say once per 2-5 minutes. You should have timeout timer. If heartbeat doesn't in 5 minutes you are writting it and after n times of absence of heartbeats you closes connection (the threshold for quantity of missing heartbeats (3-10)). This was the bestest way to be sure that servers are working and connection still alive. Because we met situation when server hanging in some state and keeps connection open but doesn't work and client thinks it is Ok. But is not. Here the values for heartbeat (every 2-5 minutes) and threshhold for missing hearbeats 3-10 are taken from real life. I hope I described this clear and it will help you (ask if ...) alex from JavaFaq http://www.erudite-center.com/java