Пример #1
0
 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();
 }
 private void connectUsingFactory(ConnectionConfigurationFactory factory) throws FriendException {
   ConnectionConfigurationFactory.RequestContext requestContext =
       new ConnectionConfigurationFactory.RequestContext();
   while (factory.hasMore(configuration, requestContext)) {
     ConnectionConfiguration connectionConfig =
         factory.getConnectionConfiguration(configuration, requestContext);
     connection = new XMPPConnection(connectionConfig);
     connection.addRosterListener(new RosterListenerImpl());
     LOG.infof(
         "connecting to {0} at {1}:{2} ...",
         connectionConfig.getServiceName(),
         connectionConfig.getHost(),
         connectionConfig.getPort());
     try {
       connection.connect();
       return;
     } catch (org.jivesoftware.smack.XMPPException e) {
       LOG.debug(e.getMessage(), e);
       requestContext.incrementRequests();
     }
   }
   throw new FriendException("couldn't connect using " + factory);
 }
Пример #3
0
 /**
  * Returns the port number of the XMPP server for this connection. The default port for normal
  * connections is 5222. The default port for SSL connections is 5223.
  *
  * @return the port number of the XMPP server.
  */
 public int getPort() {
   return config.getPort();
 }