如何保持XMPP连接稳定在Android上与(a)smack? [英] How to keep a XMPP connection stable on Android with (a)smack?

查看:692
本文介绍了如何保持XMPP连接稳定在Android上与(a)smack?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asmack-android-7-beem库为Android。我有一个后台服务运行,如我的应用程序保持活着。但是迟早会有XMPP连接死机,没有任何通知。服务器说客户端仍然在线,但没有发送或接收数据包。

I use asmack-android-7-beem library for Android. I have a background service running, such as my app stays alive. But sooner or later XMPP connection dies without any notice. The server says that the client is still online but no packets are sent or received.

例如,当其他客户端有新的存在时,客户端不接收任何存在数据包。我有XMPPConnection作为我的主要Application类的属性。

在连接之前设置 ConnectionConfiguration config.setReconnectionAllowed(true)
但重新连接不会发生。 XMPPConnection connection.isConnected()返回true。

For example the client doesn't receive any presence packets when other clients have a new presence. I have XMPPConnection as an attibute of my main Application class.
I set ConnectionConfiguration config.setReconnectionAllowed(true) before the connection was made.
But reconnection doesn't happen. XMPPConnection connection.isConnected() returns true.

因此客户端不知道连接实际上丢失了。

So the client is not aware that connection is actually lost.

有任何方法保持连接活动?

Is there any way to keep the connection alive?

推荐答案

当使用asmack在你的应用程序中放置一些代码,使Dalvik加载ReconnectionManager类并运行它的静态初始化块:

When using asmack put some code like this in your app to make Dalvik load the ReconnectionManager class and run it's static initialization block:

static {
    try {
        Class.forName("org.jivesoftware.smack.ReconnectionManager");
    } catch (ClassNotFoundException ex) {
        // problem loading reconnection manager
    }
}

这篇关于如何保持XMPP连接稳定在Android上与(a)smack?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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