The first is the cpu going to sleep for a too long time sometimes causing timeouts on the server i think.
Possible, the key aspects here are
-
The TCP connection should have a long timeout of (min(s2cPingInterval, c2sPingInterval) + 30min)
-
The server should have a long grace period where it awaits Pongs from the client. If an Android device is in sleep, the Ping-Pong lag can be sometimes around 5-10 minutes
I think i can resolve this by waking the device up and sending ping at the max time before the server times out.
You usually want to avoid that at all costs. Instead identify the exact reason the connection is terminated (e.g. is it the server? On XMPP or TCP layer?) and take appropriate countermeasures (like the one mentioned above).
. I think the internal reconnectionmanager from smack is not very suitable for android.
Right, I also recommend to disable the ReconnectionManager on Android. Of course this means that you have to implement your own reconnection logic and you need to know what you are doing.
While the ReconnectionManager loops the cpu goes into sleep again and stops smack from reconnecting.
This is not my obersvation. I test on stock ROMs and Cyanogenmod. The CPU is never completly shut off and TCP sockets are not closed. Everything just takes longer in terms of minutes instead of seconds.
org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:3 52)
org.jivesoftware.smack.TCPConnection.login(TCPConnection.java:236)
org.jivesoftware.smack.TCPConnection.connect(TCPConnection.java:883)
It’s hard to tell what’s going on there without knowing at least the Exception and the used aSmack version. I appreciate that you striped away unecessary information, but the Exception Typ would have been helpfull here.
Solution for the second problem seems to disable the ReconnectionManager and do the reconnection attempts with the AlarmManager.
If you really need to wake up the device to ensure are more responsive connection (not sure if this is really your use case), then AlarmManager is the way to go.
I don’t know if it is reasonable to integrate a special reconnection mechanism for android in smack itself?
Smack, especially the newer versions. Provide callbacks to inform the user about state changes of the XMPPConnection. You can easly implement your own reconnection logic on top of that. In fact, that is what MAXS does.
Another thing i noticed is, if i type emoji smilies with the stock android keyboard (hold return) the connection goes down without any exceptions.
I doubt that a connection in Smack can go down without any callbacks involved. What likely happens ist that the server closes the stream because it thinks the emojis are not allowed in the stream. In that case, Smack would invoke the connectionClosedOnError(Exception) callback with a “socket closed” Exception or the like.