简体   繁体   English

eJabberd 管理员在断开连接 / Android XMPP Smack 后仍将用户视为在线

[英]eJabberd admin still sees user as ONLINE after .disconnect / Android XMPP Smack

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.我正在为 Android(本机 Java)使用 eJabberd 和 Smack 我一直在尝试以各种可以想象的方式调用.disconnect()以断开连接并将用户设置为离线,但在 eJabberd 管理员上,它始终在线,即使在成功之后断开。 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() {}所有这些尝试都会导致 ConnectionListener 触发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];我的 iOS 版本,每当我调用[connection disconnect] 时; and go to my eJabberd admin, the user is shown as OFFLINE (not listed in the Online Users page).和 go 到我的 eJabberd 管理员,用户显示为离线(未在“在线用户”页面中列出)。

Did I miss something here?我在这里错过了什么吗?

-- --

He are the tags Smack is sending to eJabberd server according to its own debugger:他是 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[myuser@ejabberd.mydomain.com/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'/>

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.问题是我的 XMPPManager 使用相同的登录凭证连接/登录用户两次,为同一用户保持两个不同的连接。

So whenever I did .disconnect();所以每当我做.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.我的解决方案是让我的 XMPPManager 成为 singleton 并且一次只允许一个用户连接。

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.所以我在我的方法连接开始后立即添加了一个 static Boolean 设置为 true 。 This way I'd know if I already started a connection/login attempt, and not allow another connection while it's busy connecting:这样我就知道我是否已经开始连接/登录尝试,并且在它忙于连接时不允许另一个连接:

if(busyConnecting) {
       return;
}
busyConnecting = true;

We can also use this:我们也可以使用这个:

XMPPTCPConnection.setUseStreamManagementDefault(false);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM