Ping isn't working properly when connection goes down

I have used the PingManager to implement the XEP-0199: XMPP Ping – sever to client ping.

But the issue with this approach is when the wifi is ON but the network link is down , I am not getting a ping from a server and not even my PingFailed listener is getting fired.

So how can I check connection is alive because sometimes isConnection and isAuthentication returns true itself , even if the session is not closed at server. so if pingFailed funcitons works or is there any function exist were i can hook up in coming packet and check with the outgoing ping then in that case i can create a new xmpp connection to server and give seemless experience to the user

here is my code.

public void InitializePingManager(){

mPingManager = PingManager.getInstanceFor(xmpp);

mPingManager.setDefaultPingInterval(1000*50);

mPingManager.setPingInterval(1000*50);

mPingManager.registerPingFailedListener(new PingFailedListener(){

@Override

public void pingFailed() {

// TODO Auto-generated method stub

Log.e(“PING” , “ping failed”);

}

});

I use the latest version aSmack lib(asmack-android-8-4.0.1-SNAPSHOT-2014-06-22) have also faced the same issue, enable PingManager, but when the connection with Server is down, the pingFail callback and ConnectionListener all not be triggered.

Also I tried to enable auto reconnection as below code. but it still not work.

conf.setReconnectionAllowed(true);

conf.setSendPresence(true);

try{

Class.forName(“org.jivesoftware.smack.ReconnectionManager”);

}catch(Exception e){

e.printStackTrace();

}

anyone else have the same issue?

How do you know that a Ping was send while the connection was down?

1 Like