Quantcast
Channel: Ignite Realtime : Unanswered Discussions - Support
Viewing all articles
Browse latest Browse all 4979

Maintain XMPP connection

$
0
0

Hello everyone,

 

New with Smack, I've encapsulated the creation of my xmpp connection into the following function:

 

public AbstractXMPPConnection createConnection() {

       SmackConfiguration.DEBUG = true;

       AbstractXMPPConnection conn;

 

        // build connection
        XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();

       configBuilder.setServiceName(P2PConstants.P2P_CONF_DOMAIN);

       configBuilder.setHost(P2PConstants.P2P_CONF_SERVER);

       configBuilder.setPort(P2PConstants.P2P_CONF_PORT);

       configBuilder.setCustomSSLContext(createSSLContext());

       configBuilder.setHostnameVerifier(new P2PHostnameVerifier());

       configBuilder.setResource("");

       conn = new XMPPTCPConnection(configBuilder.build());

 

        // set reconnection policy
        ReconnectionManager connMgr = ReconnectionManager.getInstanceFor(conn);

        if (P2PConstants.P2P_RECONNECTION_ENABLED)

            connMgr.enableAutomaticReconnection();

        else
                 connMgr.disableAutomaticReconnection();

       connMgr.setReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);

       connMgr.setFixedDelay(P2PConstants.P2P_RECONNECTION_DELAY_S);

 

        // set reconnection default policy
        ReconnectionManager.setEnabledPerDefault(P2PConstants.P2P_RECONNECTION_ENABLED);

       ReconnectionManager.setDefaultReconnectionPolicy(ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);

       ReconnectionManager.setDefaultFixedDelay(P2PConstants.P2P_RECONNECTION_DELAY_S);

 

        // set ping interval
        PingManager pingManager = PingManager.getInstanceFor(conn);

        pingManager.setPingInterval(120);

 

        // set default ping interval
        PingManager.setDefaultPingInterval(120);

      

   return conn;

}

 

At application level, I register a connectionListener to monitor the connection.

 

Two questions now:

  • What is the best way to maintain the connection ?
    • register a connectionListener and explicitely ask for reconnection when connection has been lost ?
    • let the reconnection manager
  • When running my android app while connected and authenticated, if a deactivate the network, nothing happens. The socket is probably closed but Smack does not see it....

 

Thanks a lot for your support on your so helpful library,

 

Pierre


Viewing all articles
Browse latest Browse all 4979

Trending Articles