powered by Jive Software

How will smack api (4.1) handle connection losses /reconnects/ etc

I am looking to create an IM app for Android. So , instead of using their GCM , I decided to use a pure XMPP client . Smack is the best for this . I would like to know how Smack will handle connection losses /drops /reconnects in Android. If there is no internet connection,etc, does smack have built-in apis to handle that, or will I need to implement it myself ?

Also, I would like to know approximately ,how much battery life smack will use ?

Thank you.

1 Like

1.) Regarding maintaining connectivity If you use “smack-bosh” the connectivity will be maintained until you call disconnect

2.) no internet connection will not be detected by smack, you have to write your broadcast listener and accordingly call the respective functions to re establish

3.) Smack does not have build in mechanism to detect the internet availability, it will throw socket timeout and disconnect

4.) battery life as per my testing approximately 0.1% for 30 minutes

battery life as per my testing approximately 0.1% for 30 minutes
Battery life depends heavily on your usage pattern of the XMPP connection. If you just use the connection to push a message to the device once a day, the impact on battery life will be not measurable.

Also note that using XMPP over TCP is more efficient then BOSH, but keeping a TCP connection to the server established on mobile devices is not a trivial task.

Could anybody tell me how Xabber (Android app) does it ?

Hi Gupta,

https://github.com/redsolution/xabber-android/blob/master/app/src/main/java/org/ jivesoftware/smack/PacketWriter.java

If you check the code line number 391 to 436

It uses “org.jivesoftware.smackx.packet.Ping” ( XEP-0199: XMPP Ping )

It will send a ping every X number of milliseconds configurable from the SmackConfiguration

Important Note: Xabber is not using the SMACK 4.1.x directly, It uses an older version of smack as a pull and with further customization.

Hope it helps


How smack-bosh helps in maintaining connection losses.
I am having the similar issue with connectivity loses

for now i am having following dependencies for android:
implementation "org.igniterealtime.smack:smack-android-extensions:4.2.2"
implementation “org.igniterealtime.smack:smack-tcp:4.2.2”

it connect, authenticate and sending, recieving message works fine.

but the problem is of connection losses. Can you pls tell me smack-bosh usage.

Smacks BOSH implementation extends the AbstractXMPPConnection class, so you can see it as an alternative to smack-tcp.
Please check XEP-0206: XMPP Over BOSH for information about how BOSH works.