I found that Openfire always ping the client after a client session expired every 3 minutes. The reason for it is that the smack 4.2.1 does not ping the server periodically, and causes the session expiration.
How to deal with the problem?
Not sure if this is the ideal way to improve this, but you could attach PingManager to your connection
mConnection = new XMPPTCPConnection(conf);
mConnection.addConnectionListener(this);
pingManager = PingManager.getInstanceFor(mConnection);
and periodically ping the server once you are connected ,below is an example on android:
private Timer pingTimer;
private TimerTask pingTimerTask = new TimerTask() {
@Override
public void run() {
try {
if(pingManager.pingMyServer())
{
Log.d(TAG,"Ping successful");
}else {
Log.d(TAG,"Ping NOT successful");
}
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};