确定插座连接状态 - 机器人 [英] determine socket connection state - android

查看:80
本文介绍了确定插座连接状态 - 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用套接字连接到我的服务器的应用程序。很多时候应用处于休眠时,它并不需要发送的信息来回服务器。出现这种情况时,偶尔会断开连接。

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?

我用的一些应用程序做的正是这一点,会弹出一个对话框,提示重新连接。我敢肯定,我可以$ C C此$符合某种平的方法激发秒每X号,但我想知道如果插座类有一些内置的这些其他应用程序正在使用?

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?

推荐答案

您使用服务来处理这个Socket连接到你的服务器(它可能是一个好主意)。如果/当你是,你可以创建一个平的方法,在服务线程。

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.

这篇关于确定插座连接状态 - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆