private void connectUsingConfiguration(ConnectionConfiguration config) throws XMPPException {
   String host = config.getHost();
   int port = config.getPort();
   try {
     if (config.getSocketFactory() == null) {
       this.socket = new Socket(host, port);
     } else {
       this.socket = config.getSocketFactory().createSocket(host, port);
     }
     if (ConnectionConfiguration.SecurityMode.legacy == config.getSecurityMode()) {
       try {
         enableEncryption(false);
       } catch (Exception e) {
         String errorMessage =
             "Could not enable SSL encryption while connecting to " + host + ":" + port + ".";
         throw new XMPPException(
             errorMessage,
             new XMPPError(XMPPError.Condition.remote_server_error, errorMessage),
             e);
       }
       usingSSL = true;
     }
   } catch (UnknownHostException uhe) {
     String errorMessage = "Could not connect to " + host + ":" + port + ".";
     throw new XMPPException(
         errorMessage,
         new XMPPError(XMPPError.Condition.remote_server_timeout, errorMessage),
         uhe);
   } catch (IOException ioe) {
     String errorMessage = "XMPPError connecting to " + host + ":" + port + ".";
     throw new XMPPException(
         errorMessage, new XMPPError(XMPPError.Condition.remote_server_error, errorMessage), ioe);
   }
   initConnection();
 }
 /**
  * Creates a new XMPP connection using the specified connection configuration.
  *
  * <p>
  *
  * <p>Manually specifying connection configuration information is suitable for advanced users of
  * the API. In many cases, using the {@link #XMPPConnection(String)} constructor is a better
  * approach.
  *
  * <p>
  *
  * <p>Note that XMPPConnection constructors do not establish a connection to the server and you
  * must call {@link #connect()}.
  *
  * <p>
  *
  * <p>The CallbackHandler will only be used if the connection requires the client provide an SSL
  * certificate to the server. The CallbackHandler must handle the PasswordCallback to prompt for a
  * password to unlock the keystore containing the SSL certificate.
  *
  * @param config the connection configuration.
  * @param callbackHandler the CallbackHandler used to prompt for the password to the keystore.
  */
 public XMPPConnection(ConnectionConfiguration config, CallbackHandler callbackHandler) {
   super(config);
   config.setCallbackHandler(callbackHandler);
 }