使用 aSmack 丢失消息
我在我的 Android 应用程序中使用 aSmack 从我的桌面 Jabber 客户端接收消息。这工作正常,即使我的 Android 手机处于离线状态(正确关闭连接后),它也会在下次登录后收到离线消息。
但是,当我在手机上进入飞行模式或关闭手机时,连接突然关闭(没有在 Connection
对象上调用 disconnect()
)在我的 Desktop-Jabber 客户端的联系人列表中保持“在线”一段时间,我可以向它发送消息。然而这些消息从未到达。即使手机再次登录服务器。这些消息丢失了。
有谁知道如何解决这个问题?在聊天中丢失消息是不可能的。 :)
编辑:添加测试代码
广播接收器:http://pastebin.com/cFLzGXgy
服务: http://pastebin.com/wLpQCQfT
第一个是启动服务的 BroadcastReceiver(第二个URL)每次电话连接到网络时。
PS:这只是一个测试代码!如果您想使用/测试它,您必须更改服务器/用户名/密码。
i'm using aSmack in my Android app to receive messages from my Desktop-Jabber-client. This works fine and even if my android phone is offline (after the connection was closed properly) it will receive the offline messages after the next login.
But when i enter the airplane-mode on the phone or shutdown the phone so that the connection is abruptly closed (without calling disconnect()
on the Connection
-object) the phone stays "online" in the contact-list of my Desktop-Jabber-client for a while and i can send messages to it. However these messages never arrive. Even though the phone logs in to the server again. These messages are lost.
Does anyone know how to fix this issue? Losing messages in a chat is not an option. :)
EDIT: Added Test-Code
BroadcastReceiver: http://pastebin.com/cFLzGXgy
Service: http://pastebin.com/wLpQCQfT
The first one is a BroadcastReceiver starting the service (second URL) each time the phone is connected to a network.
PS: This is only a test-code! You must change the server/username/password if you want to use/test it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当消息到达时,您可以尝试将客户端 B 发送的消息发送到客户端 A。问题是,如果客户端 A 离线(没有连接中断),则传递的确认不会发送,直到用户收到消息,并且客户端 B 无法重新发送消息。
You can try to send delivered message from client b to client A when the message arrival. The problem is if the client A is offline (no connection break) the delivered confirm don't send until the user receives the message and the client B can't re-send the message.
您可以尝试使用 Smackx 消息发送接收消息的确认活动
这将确保消息的传递,否则您将采取纠正措施。
you can try to send acknowledgement of receiving the message using Smackx Message Events
this will assure the message is delivered else you take corrective action.
当您的连接中断时,就会出现此问题。
您需要启用“流管理”XEP-198 的连接来实现此消息。请参阅此博客:http://op-co.de/blog/posts/XEP -0198/ 基本上它允许节确认和流恢复,这正是您想要做的,以防万一。所以您应该等到 smack 4.1 发布。
this problem occurs when your connection broke.
You need "Stream Management" XEP-198 enabled connections to achieve this messages. refer to this blog : http://op-co.de/blog/posts/XEP-0198/ Basically it allows for stanza acknowledgement and stream resumption, which is exactly what you want to do in case.so you should wait till smack will 4.1 release.