powered by Jive Software

Recommended way to Logout

Smack: 4.4.4
XMPP Server: eJabberd

Problem:
I want user to logout immediately so that Server cannot send message to the disconnected client and loose that message. I have tried disconnect(presence) but Psi+ sees me as connected. Here is my latest attempt that didn’t work also

fun logout() {
    connection.sendStanza(
        MessageBuilder.buildPresence()
            .ofType(Presence.Type.unavailable)
            .build()
    )
    connection.instantShutdown()
}

How do I do instant logout?

Here is relevant log from eJabberd. Note that even after 300secs am still online in Psi+

Closing c2s connection for stefano@localhost/App: Connection failed: connection closed; waiting 300 seconds for stream resumption

Where do I go wrong?

Changed to disconnect and moved to OnStop and all started working

Yep, using instantShutdown() is a recipe for dangling online connections. In fact, it was explicitly designed for that. You want a clean disconnect, and that is what, no suprise, AbstractXMPPConnection.disconnect() does. :slight_smile:

I see. Disconnect works great.
One more side question, if I just change presence to unavailable will that stop the server from sending messages or I have to do actual disconnection?

Strictly speaking not. Please refer to the XMPP RFCs for the XMPP routing rules, especially “available session” vs “connected session” (if I remember the terms correctly).

1 Like

Thank you.
I will check the RFC!

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.