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