Reputation: 11119
I have an application that uses sockets to connect to my server. A lot of times the application lies "dormant" when it doesn't need to send info back and forth to the server. When that happens, occasionally it will disconnect.
How can I determine when the socket has disconnected and then try to re-establish a connection?
I've used some applications that do exactly this and will pop up a dialog box that indicates "reconnecting". I'm sure I could code this in with some kind of "ping" method that fires every X number of seconds, but I'm wondering if the socket class has something built in that these other apps are using?
Upvotes: 0
Views: 845
Reputation: 33901
Are you using a Service to handle this Socket connection to your server (it would probably be a good idea). If/when you are, you can create the "ping" method as a thread in your service.
Upvotes: 1