eJabberd 管理员在 .disconnect / Android XMPP Smack 后仍将用户视为在线
我正在使用适用于 Android 的 eJabberd 和 Smack(本机 Java) 我一直在尝试以各种可以想象的方式调用 .disconnect() 来断开连接并将用户设置为离线,但在 eJabberd 管理上,它始终处于在线状态,即使在成功断开连接之后也是如此。 我使用的一些代码:
connection.disconnect();
还使用了:
try {
connection.sendStanza(
MessageBuilder.buildPresence()
.ofType(Presence.Type.unavailable)
.build()
);
} catch (SmackException.NotConnectedException | InterruptedException e) {
e.printStackTrace();
}
另外:
PresenceBuilder presenceBuilder = connection.getStanzaFactory()
.buildPresenceStanza();
presenceBuilder.ofType(Presence.Type.unavailable);
Presence presence = presenceBuilder.build();
try {
connection.disconnect(presence);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
所有这些尝试都会导致 ConnectionListener 触发 public void connectionClosed() {}
这意味着连接已成功关闭。
那么为什么即使在成功断开连接之后,它仍然显示为在线(在线用户)?
我的 iOS 版本,每当我调用 [连接断开];并转到我的 eJabberd 管理员,该用户显示为离线(未在“在线用户”页面中列出)。
我在这里错过了什么吗?
--
他是 Smack 根据其自己的调试器发送到 eJabberd 服务器的标签:
D/SMACK: SENT (1):
<presence id='3HD1T-11' type='unavailable'/>
<a xmlns='urn:xmpp:sm:3' h='16'/>
</stream:stream>
D/SMACK: RECV (1):
</stream:stream>
D/SMACK: XMPPConnection closed (XMPPTCPConnection[[email protected]/3432235344…3890484] (1))
D/SMACK: RECV (0):
<r xmlns='urn:xmpp:sm:3'/>
D/SMACK: SENT (0):
<a xmlns='urn:xmpp:sm:3' h='16'/>
I'm using eJabberd and Smack for Android (Native Java)
I've been trying to call .disconnect() in every imaginable way to disconnect and set the user as OFFLINE, but on eJabberd admin, it's always ONLINE, even after a successful disconnect.
Some codes I used:
connection.disconnect();
Also used:
try {
connection.sendStanza(
MessageBuilder.buildPresence()
.ofType(Presence.Type.unavailable)
.build()
);
} catch (SmackException.NotConnectedException | InterruptedException e) {
e.printStackTrace();
}
Also:
PresenceBuilder presenceBuilder = connection.getStanzaFactory()
.buildPresenceStanza();
presenceBuilder.ofType(Presence.Type.unavailable);
Presence presence = presenceBuilder.build();
try {
connection.disconnect(presence);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
All these attempts results in the ConnectionListener trigger the
public void connectionClosed() {}
Which means the connection was successfully closed.
SO WHY IS THIS STILL SHOWING AS ONLINE (Online Users) EVEN AFTER SUCCESSFULLY DISCONNECTED?
My iOS version, whenever I call [connection disconnect]; and go to my eJabberd admin, the user is shown as OFFLINE (not listed in the Online Users page).
Did I miss something here?
--
He are the tags Smack is sending to eJabberd server according to its own debugger:
D/SMACK: SENT (1):
<presence id='3HD1T-11' type='unavailable'/>
<a xmlns='urn:xmpp:sm:3' h='16'/>
</stream:stream>
D/SMACK: RECV (1):
</stream:stream>
D/SMACK: XMPPConnection closed (XMPPTCPConnection[[email protected]/3432235344…3890484] (1))
D/SMACK: RECV (0):
<r xmlns='urn:xmpp:sm:3'/>
D/SMACK: SENT (0):
<a xmlns='urn:xmpp:sm:3' h='16'/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是我的 XMPPManager 使用相同的登录凭据连接/登录用户两次,为同一用户保留两个不同的连接。
因此,每当我执行
.disconnect();
时,它都会终止其中一个连接,但使另一个连接仍然在线。我的解决方案是使我的 XMPPManager 成为单例,并且一次只允许一个用户连接。
由于连接是异步的,如果它调用两次(出于任何疯狂的原因),它仍然会连接同一用户两次。
因此,我在方法连接开始后立即添加了一个静态布尔值设置为 true。
这样我就知道我是否已经开始连接/登录尝试,并且在忙于连接时不允许另一个连接:
我们也可以使用这个:
The issue was that my XMPPManager was connecting/login a user twice with the same login credentials, keeping two different connections for the same user.
So whenever I did
.disconnect();
it was terminating one of the connections, but leaving the other one still online.My solution was to make my XMPPManager a singleton and allowing only a single user connection at a time.
Since connection is async, if it called twice (for any crazy reason), it would still connect twice the same user.
So I added a static Boolean set to true right after my method connecting starts.
This way I’d know if I already started a connection/login attempt, and not allow another connection while it’s busy connecting:
We can also use this: