Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jabber user going offline: Why the two different scenarios?

I have an Android client working in tandem with ejabberd XMPP server.

Observations:

  • Scenario 1: When I swipe-right the app (kill the app), the user goes offline on the server immediately. Its status is changed to offline at that very instant.

  • Scenario 2: However, when I simply shut-down the Wi-fi connectivity (data) of my Android Jabber client, there is a noticeable lag of a few minutes for the user to be marked offline on the server.

I can’t figure out what is the fundamental difference in the two processes.

What could be done in Scenario 2 to make it go offline immediately?

like image 223
Raina M Avatar asked Oct 31 '22 03:10

Raina M


1 Answers

Scenario 1: When I swipe-right the app (kill the app), the user goes offline on the server immediately. Its status is changed to offline at that very instant.

In above case your Android xmpp client is sending presence as unavailable before closing your Android application, maybe your Android XMPP client is maintaining a background service which in turn maintains a persist XMPP connection (TCP socket) to XMPP server, when you close your application onDestroy() method of service will be called and in that one can check if XMPP connection is still connected. If yes then send presence as unavailable which will safely make user as offline on server and then disconnect XMPP connection (socket).

Scenario 2: However, when I simply shut-down the Wi-fi connectivity (data) of my Android Jabber client, there is a noticeable lag of a few minutes for the user to be marked offline on the server.

As I mentioned earlier, Android devices can maintain a persist XMPP connection in a service, when you turn off wifi and your XMPP connection (TCP socke) to server is still connected, there is no safe removal of user from XMPP server [client can't send presence as unavailable] means connection is just-hang up and Android client/XMPP server doesn't have knowledge of it. In such case now server will figure out client is hangup by client ideal time period [i.e there is no communication on socket for a fixed interval], and make user as offline. This process is time consuming so that you are seeing lag of a few minutes.

What could be done in Scenario 2 to make it go offline immediately?

You can configure XMPP server and make client

As this problem can be handled from XMPP client and server, from client you can fixed interval time ping, if you keep ping duration small enough you can detect lost connection (like broken pipe on socket), same way on server side if you keep ping inter [remember this is server to client ping] small you can detect loss of connection.

As I can see you are using ejabberd as your XMPP server, details given on this link says,

How to detect a dead connection?

One way to detect a dead connection is to ping the client periodically and to kill the connection if the client doesn't respond. This can be done using mod_ping. However, these ping packets might wake up the client's radio, so a short ping interval might drain mobile batteries. Therefore, it's not generally recommended to use an interval of less than a few minutes. Either way, there's always some time window where messages can be lost.

like image 163
Dev Avatar answered Nov 17 '22 07:11

Dev