powered by Jive Software

Closing the socket and keeping the session

Hello, first of all I apologize if this is not the correct place to ask such a question.

I’m using Smack 4.2.2, the latest release version.
I’m wondering if it’s possible to disconnect from server (E-Jabberd back-end) without actually closing the stream. Basically I want to close the socket but keep the session so I can rebind with the same session. (my session is 24 hours)

Right now I’m using disconnect() from AbstractXMPPConnection, but this is sending a stanza with presence unavailable and also sending the follow </stream:stream> stanza. Is there a solution for this ?

Why would you want to do that?

To avoid doing a full reconnect every time the client opens the app in the span of 24 hours by establishing a past session that has not been destroyed yet. If I send </stream:/stream> stanza the next time the user opens its app it will be a full reconnect (takes a while 4-5 seconds depending on internet speed).

Why is the session closed/disconnected in the first place?

Sorry for not providing enough details.

Basically the session is being established when I send a custom stanza to register for push notifications with E-Jabberd and in order to receive such pushes I need to disconnect(close the socket), but I can still have an open session. So if the user goes to background for more than one minute, I would like to close only the socket.

So it appears you are using XEP-0357 for no reason. Why not simply leave the XMPP connection open and use XEP-0352: Client State Indication?

1 Like

I see, so you are suggesting to keep the connection through a sticky service that is always open and minimize the impact on battery by stopping unnecessary stanzas while the app is in background or killed.

Thank you for your help, I will look into it, if my server provides XEP-0352 as they are “recommending” me to go with push notifications.

If XEP-0352 and -0357 use the same trigger conditions, then using -0357 on Android has only the advantage that the GCM will possibly bundle and defer your push with other pushes…

But I recommend the combination of XEP-0352 and XEP-0397: Instant Stream Resumption on Android.

Hi @dani2pix,
How did u check the stanza being sent using smack client?

See the Smack Wiki for how to capture stanza logs.