I have a client-server system, both sides written by me, and I would like to put the clients in an 'offline' state when the server disconnects/dies, and then automatically bring them back 'online' when the server is available again.
For the first part, I listen for channel faulted events and handle that by setting the client to offline. I then start calling a 'ping' service on the server (every 30 sec.) which just returns a bool if it is alive. Once it is alive the client gets the bool and switches back online.
This all works, the problem I am having is that when the client calls the ping service and the server is down, no response is sent (obviously) and eventually, after about 2mins I get an endpoint not found exception. By this time I have already tried 3-4 more pings and hence have 3-4 exceptions brewing.
My question is, how can I deal with the ping service more gracefully? Ideally I would like to periodically call a service that lets me know if it is online, and instantly lets me know if it is not.
What about this:
That way, if you're in "Ping mode", you get your responses (or timeouts) quickly and you can detect the availability of the service quickly.