为啥当 XMPP 连接断开时,出席类型用户从不可用变为可用
Posted
技术标签:
【中文标题】为啥当 XMPP 连接断开时,出席类型用户从不可用变为可用【英文标题】:Why when the XMPP connection disconnect the presence type user change from unavailable to available为什么当 XMPP 连接断开时,出席类型用户从不可用变为可用 【发布时间】:2014-11-14 05:27:06 【问题描述】:当我关闭应用程序并停止执行 ping 时如何正确注销?
当我在下面运行注销时,每一行代码都可以正常工作,
但如果我运行代码行:
Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
presence.setStatus(connection.getUser() + status);
connection.sendPacket(presence);
我让用户离线/不可用。//But the connection alive
然后我想断开连接,所以我运行线路代码。
connection.disconnect();//I get user online/available and connection die.
当连接中断时,我遇到了更多问题,例如 ping。
11-13 21:55:02.820: D/SMACK(7399): 09:55:02 PM SENT (1385370112):
11-13 21:55:32.820: D/SMACK(7399): 09:55:32 PM SENT (1385370112):
11-13 21:56:02.820: D/SMACK(7399): 09:56:02 PM SENT (1385370112):
11-13 21:56:32.820: D/SMACK(7399): 09:56:32 PM SENT (1385370112):
11-13 21:57:02.820: D/SMACK(7399): 09:57:02 PM SENT (1385370112):
11-13 21:57:32.820: D/SMACK(7399): 09:57:32 PM SENT (1385370112):
11-13 21:58:02.824: D/SMACK(7399): 09:58:02 PM SENT (1385370112):
11-13 21:58:32.824: D/SMACK(7399): 09:58:32 PM SENT (1385370112):
11-13 21:59:02.824: D/SMACK(7399): 09:59:02 PM SENT (1385370112):
11-13 21:59:32.824: D/SMACK(7399): 09:59:32 PM SENT (1385370112):
public void logOut(boolean unavailable, String status)
if (isConnectionAlive() || reConnectAndAuth())
Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
presence.setStatus(connection.getUser() + status);
connection.sendPacket(presence);
pm = null;
connection.disconnect();
//iscNNcet();
Log.w("LogOut","LogOut");
【问题讨论】:
【参考方案1】:我通过下一个代码解决了这个问题。
public void logOut(boolean unavailable, String status,Context orgContext)
if (isConnectionAlive() || reConnectAndAuth(orgContext))
Presence presence = new Presence(org.jivesoftware.smack.packet.Presence.Type.unavailable);
presence.setStatus(connection.getUser() + status);
pm = null;
try
connection.disconnect(presence);
catch (Exception exception)
exception.printStackTrace();
connection.disconnect();
Log.w("LogOut", "LogOut");
【讨论】:
以上是关于为啥当 XMPP 连接断开时,出席类型用户从不可用变为可用的主要内容,如果未能解决你的问题,请参考以下文章
Xshell如何设置,当连接断开时保留Session,保留原文字