开发者

determine socket connection state - android

开发者 https://www.devze.com 2023-01-13 14:33 出处:网络
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, occas

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 "reconnect开发者_如何学JAVAing". 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消