Thursday, June 16, 2016

ReconnectionManager is not working correctly

Leave a Comment

I am using smack library to implement chat solution in android. It is making connection with openfire perfectly but reconnection is not working at all.

I have a lost a connection on a device, on connection receive it does not reconnect or call any callbacks of reconnect. Please suggest how we can reconnect to openfire using ReconnectManager.

private boolean openConnection(String account, String password) {     try {         if (null == xmppConnection || !xmppConnection.isAuthenticated()) {             XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();             config.setHost(Constants.XMPP_SERVER_DOMAIN);             config.setServiceName(Constants.XMPP_SERVER_DOMAIN);             config.setPort(Constants.XMPP_SERVER_PORT);             config.setUsernameAndPassword(account, password);             //config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);             config.setCompressionEnabled(true);             config.setDebuggerEnabled(true);              TLSUtils.acceptAllCertificates(config);              xmppConnection = new XMPPTCPConnection(config.build());             xmppConnection.setPacketReplyTimeout(10000);             ReconnectionManager.getInstanceFor(xmppConnection).enableAutomaticReconnection();             connectionListener = new XmppConnectionListener();             packetListener = new XmppPacketListener();              xmppConnection.addAsyncPacketListener(packetListener, new PacketFilter() {                 @Override                 public boolean accept(Stanza packet) {                     return true;                 }             });              xmppConnection.addConnectionListener(connectionListener);             xmppConnection.connect().login();             return true;         }     } catch (XMPPException xe) {         xe.printStackTrace();         xmppConnection = null;     } catch (IOException io) {         io.printStackTrace();         xmppConnection = null;     } catch (SmackException se) {         se.printStackTrace();         xmppConnection = null;     } catch (NoSuchAlgorithmException e) {         e.printStackTrace();         xmppConnection = null;     } catch (KeyManagementException e) {         e.printStackTrace();         xmppConnection = null;     }     return false; } 

XmppConnectionListener.java

public class XmppConnectionListener implements ConnectionListener {       private static final String TAG = "XmppConnectionListener";       @Override      public void reconnectionSuccessful() {          Log.d(TAG, "reconnectionSuccessful()");      }       @Override      public void reconnectionFailed(Exception arg0) {          Log.d(TAG, "reconnectionFailed()");      }       @Override      public void reconnectingIn(int arg0) {          Log.d(TAG, "reconnectingIn()");      }       @Override      public void connectionClosedOnError(Exception arg0) {          Log.d(TAG, "connectionClosedOnError()");      }       @Override      public void connected(XMPPConnection connection) {          Log.d(TAG, "connected()");      }       @Override      public void authenticated(XMPPConnection connection, boolean resumed) {          Log.d(TAG, "authenticated()");       }       @Override      public void connectionClosed() {          Log.d(TAG, "connectionClosed()");      }  } 

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment