Java – smack client – the user is still online even though the connection is aborted

I use smack to build a small XMPP client / BOT to experience a very strange behavior I set up a connection and a connectionlistener and a chatmanagerlistener This works well, and then I can chat with my application running on my portable device

To test the loss of connection behavior, I'll plug in the Ethernet cable of the portable device I hope the XMPP client loses connection and the user will be set to "offline" in the user's friend list What happens is that the user is still displayed as "online" and the connectionlistener of my client is not started, whether connectionclosed or reconnection fails, otherwise

When I plug in the Ethernet cable again, it sometimes feels like the connection is still alive Offline messages are processed and I can chat again as before Other times, my client is completely inaccessible and out of order, as if all the listeners have disappeared... But no interest has been thrown out

This is a very strange and uncontrollable behavior, which will make the whole client unavailable to me, because I can't be sure that the client will appear again after the connection is blocked

Has anyone encountered such a problem, or any hint of what (does not) happen?

I can provide my code if necessary, but it's actually just copy & paste from the smack document

Solution

You actually describe two different effects here Let's start with your question Title: even if the connection is sudden, the user is assumed to be online, so it is not cleaned up The reason is that the server has not noticed the disconnection of the client because there is no clean termination of XMPP throttling Most XMPP servers check Ping every X minutes If the client does not respond, it is disconnected and displayed offline (if it is the last connected resource of the Jid) It's not uncommon that this doesn't happen here Because sometimes you want to overtime for a long time (more than half an hour)

The same applies to the other party If you use pingmanager or pingmanagerwithalarmmanager (for Android), smack also sends XMPP Ping every X minutes Throw an exception if there is any problem with the socket used

I hope I can point you in the right direction You must debug for yourself why the connection will not be terminated, except in your case

The last thing is: even if the Ethernet cable is unplugged and reinserted, TCP connections can easily exist for a period of time There are many timeouts at all levels of the OSI model: Nat, TCP, XMPP, etc

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>