且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android / Smack:在睡眠模式下保持XMPP连接处于活动状态

更新时间:2022-03-16 23:04:20

解决此问题的确切方法是使用推送通知。

The exact way to resolve this issue is by using push notification.

在指定的空闲间隔后,即设备进入休眠状态时,XMPP连接的自然行为是断开的。

It is the natural behavior of XMPP connection to get disconnected after the specified idle interval i.e when the device goes to sleep.

来自WhatsApp的情况,它也使用相同的XMPP并维护一个服务器,它充当交换消息的包装类。此服务器检查消息状态是否已传递。 如果未发送,它会在收到消息时发送推送通知,现在在推送服务的设备端,它会检查连接是否处于活动状态并且是否经过身份验证。

Coming to the case of WhatsApp, it also uses the same XMPP and maintains a server which acts as a wrapper class on the messages exchanged. This server checks the message status whether it is delivered or not. If not delivered, it sends a push notification, now at the device end in the push service when a message is received, it checks if the connection is active and is authenticated or not.

如果未经过身份验证,则会重新建立连接。通过这种方式,大多数聊天应用程序都可以管理此超时异常。

If not authenticated, it re-establishes the connection. In this way, the most chat apps manage this timeout exception.

希望这有助于:)