powered by Jive Software

Smack can not Ping xmpp server automatically in version 4.2.1

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);


        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() {

        public void run() {
            try {
                    Log.d(TAG,"Ping successful");
                }else {
                    Log.d(TAG,"Ping NOT successful");
            } catch (SmackException.NotConnectedException e) {
            } catch (InterruptedException e) {