Search code examples
androidxmppopenfiresmackasmack

Openfire: not able to send packet after few (2-3) hours even if I already connected to the Openfire server


I am using the below software for chat application for Android

  1. XMPP server: Openfire 3.9.3
  2. XMPP Client : Asmack-android-8-4.0.4.jar

I am facing some strange behavior of an Openfire server when I change the presence of the logged-in user manually.

Below is the piece of code from my class

xmppConfig.setSendPresence(false);
// Call first time only while configuration connection
presence = new Presence(Type.available, Constant.STATUS_ONLINE, 1, Mode.available);
// Code to change the presence of user
connection.sendPacket(presence);

Normal logs where I am able to change the presence of the user (I checked on the Openfire portal and it works as accepted):

SENT (1): <presence id='z13q2-27'><status>online</status></presence>
RCV (1): <presence id="z13q2-26" from="rayan@**********.com/Smack"
 to="rayan@**********.com/Smack"><status>online</status></presence>

After some (2-3) hours when I come back to the application and try to set the presence online (I checked on the Openfire portal and this user is showing an offline presence even though I set the presence to online).

SENT (1): <presence id='z13q2-27'><status>online</status></presence>
//**** No packet replay of change presence *********

I checked the below value after the above scenario to check if the user is still connected, but I got the below result which indicates that the connection is alive and the user is still connected, but at the same time the Openfire (web)portal is showing that the user is offline,

xmppManager.getConnection().isConnected()       //Result(true)
xmppManager.getConnection().isAuthenticated()  //Result(true)
xmppManager.getConnection().isAnonymous()    //Result(false)

I am not able to send a message to someone nor receive message after above scenario.


SENT (0): <message id='9388u-21' to='rayan@*********.com' type='chat'>
<subject>nullMedia</subject><body>Test message</body><custom_data>
<aliasNmae>Robine H.</aliasNmae><profilePicUrl></profilePicUrl>
</custom_data><request xmlns='urn:xmpp:receipts'/></message>

The above is the log when I send a message after the above scenario, and here <custom_data> is my custom extension.

Even when I check the history in Openfire, there are no messages stored after the above scenario.


I am not sure whether there is an option to maintain the long-lived connection over the Openfire server (web portal) or I am doing something wrong here with the XMPP client.

Please guide me if anyone are having some thoughts about this strange situation.


Solution

  • I checked below value after above scenario to check if user still connected , but i got below result which indicate that connection is alive

    No, those are just indications that Smack isn't aware of a broken connection. There a dozens reasons why a connection could become broken without the library noticing.

    If you want to reliable check if an connection is alive, use PingManager.pingMyServer().