简体   繁体   中英

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. 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[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.

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:

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

We can also use this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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