Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smack Client - User is still 'online' although connection aborted

I experience a quite strange behavior using smack to build a small XMPP Client/Bot. I set up the connection as well as a ConnectionListener and a ChatManagerListener. This works quite fine and I can then chat with my application which is running on a portable device.

To test behavior on lost connection I plugged out the ethernet cable of the portable device. I expected the XMPP client to lose the connection and that the user will be set 'offline' in the roster of the users buddies. What happens is, that this user is still shown as 'online' and ConnectionListener of my client fires nothing, whether connectionClosed nor reconnectionFailed or else.

When I then plug the ethernet cable back in, sometimes it's like the connection has been alive all the time. The offline messages are handled and I can chat again like before. Other times my client is totally inaccessible and out of order, seems like all the listeners are gone... But no excpetions are thrown.

That's a quite strange and uncontrollable behavior that would make the whole client unusable for me, as I can't be sure that the client will come up again after connection has been arborted.

Has anybody else experienced such problems or has any hints what's (not) happening?

If needed I can provide my code, but it's actually just copy & paste from the Smack documentation.

like image 880
signpainter Avatar asked May 31 '12 14:05

signpainter


1 Answers

You are actually describing two different effects here. Let's start with the one that's named in the title of your question: The user is assumed online by the server even if the connection is abruptly, and therefore unclean, aborted. The reason is simply that the server hasn't noticed the disconnect of the client yet, as there was no clean termination of the XMPP stanza stream. Most XMPP server check the clients with an ping every X minutes. If a client does not respond it's assumed disconnected and shown offline (if it was the last connected resource for that JID). That hasn't happened here and is not uncommon. Because sometimes you want to have long timeouts (half an hour or longer).

The same applies to the other side. Smack also sends XMPP pings every X minutes if PingManager or PingManagerWithAlarmManager (for Android) is used. If there is any problem with the used socket, an exception is thrown.

I hope that I could point you into the right direction. You have to debug for yourself why the connection is not terminated with an exception in your case.

One last thing: An TCP connection can easily survive some timeout even if the Ethernet cable is plugged out and then back in. There are many timeouts on various layers of the OSI model involved: NAT, TCP, XMPP, etc.

like image 141
Flow Avatar answered Nov 09 '22 01:11

Flow