I have a client-server app where both communicate over tcp. We are planning on reusing the tcp in-built keep alive mechanism to ensure both client and server know the other guy is alive.
A few questions:
- Right now, we have done a setsockopt(..) to enable tcp keep alive and also have set the keep alive timeout values. Lets assume the application is idle. I want the application to know that the keep alive timed out ...which means the client-server connection is down. The app then has to display an error page. What is a good way for the application to know that? I believe if a tcp keep alive times out, subsequent attempts to send a msg over that socket will return a WSAENETRESET error, but I want the app to know even if it is idle and no messages are flowing.
I was thinking of doing the following: Have a loop that runs every 20s (duration may be increased/decreased) and does a setsockopt to set the keep alive to true. If the connection is broken, this call will return a WSAENETRESET error.
What would be a good keep alive interval to use?
Any issues with using the tcp in built keep alive mechanism?
Thanks in advance...