android - Jabber 用户下线 : Why the two different scenarios?

标签 android erlang xmpp ejabberd user-presence

我有一个 Android 客户端与 ejabberd XMPP 服务器协同工作。

观察:

  • 场景 1:当我向右轻扫应用(关闭应用)时,用户会立即在服务器上离线。它的状态在那一刻变为离线。

  • 场景 2:但是,当我只是关闭我的 Android Jabber 客户端的 Wi-fi 连接(数据)时,用户会明显延迟几分钟在服务器上标记为离线。

我无法弄清楚这两个过程的根本区别是什么。

在场景 2 中可以做些什么来让它立即下线

最佳答案

Scenario 1: When I swipe-right the app (kill the app), the user goes offline on the server immediately. Its status is changed to offline at that very instant.

在上述情况下,您的 Android xmpp 客户端在关闭您的 Android 应用程序之前将状态发送为不可用,也许您的 Android XMPP 客户端正在维护后台服务,当您关闭时,该服务又会维护与 XMPP 服务器的持久 XMPP 连接(TCP 套接字)您的应用程序 onDestroy() 服务方法将被调用,并且可以检查 XMPP 连接是否仍然连接。如果是,则将状态发送为不可用,这将使用户在服务器上安全地处于离线状态,然后断开 XMPP 连接(套接字)。

Scenario 2: However, when I simply shut-down the Wi-fi connectivity (data) of my Android Jabber client, there is a noticeable lag of a few minutes for the user to be marked offline on the server.

正如我之前提到的,Android 设备可以在服务中保持持久的 XMPP 连接,当您关闭 wifi 并且您与服务器的 XMPP 连接(TCP 套接字)仍然连接时,无法从 XMPP 服务器安全移除用户 [ client can't send presence as unavailable] 表示连接刚刚挂断,Android 客户端/XMPP 服务器不知道它。在这种情况下,现在服务器将通过客户端理想时间段确定客户端挂断[即在固定时间间隔内套接字上没有通信],并使用户处于离线状态。此过程非常耗时,因此您会看到几分钟的延迟。

What could be done in Scenario 2 to make it go offline immediately?

可以配置XMPP服务器和制作客户端

因为这个问题可以从 XMPP 客户端和服务器处理,从客户端你可以固定间隔时间 ping,如果你保持 ping 持续时间足够短你可以检测到丢失的连接(比如套接字上的管道断开),如果在服务器端也是如此你保持 ping inter [记住这是服务器到客户端的 ping] 小你可以检测到连接丢失。

正如我所看到的,您正在使用 ejabberd 作为您的 XMPP 服务器,详情请参见 this link说,

How to detect a dead connection?

One way to detect a dead connection is to ping the client periodically and to kill the connection if the client doesn't respond. This can be done using mod_ping. However, these ping packets might wake up the client's radio, so a short ping interval might drain mobile batteries. Therefore, it's not generally recommended to use an interval of less than a few minutes. Either way, there's always some time window where messages can be lost.

关于android - Jabber 用户下线 : Why the two different scenarios?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30347862/

相关文章:

windows - 无法让 RabbitMQ 在 Windows 10 上运行

ios - 使用 xmpp 和 openfire 向用户发送好友请求

android - asmack 没有收到多用户聊天请求

ios - 如何使用xmpp jidstr iOS sdk获取资源

arrays - 将数组传递给erlang中的函数

erlang - gen_服务器 :call with new State

android - 重定向到通知访问设置

php - 当Mysql查询包含 "SELECT * FROM..."时,可以使用哪个函数代替 get_result() ?

java - 如何减小 Tflite 模型的大小或下载并以编程方式设置?

java - AppCompatActivity 导致 Eclipse 中的应用程序崩溃