/** * Creates a new XMPP connection over TCP (optionally using proxies). * <p> * Note that XMPPTCPConnection constructors do not establish a connection to the server * and you must call {@link #connect()}. * </p> * * @param config the connection configuration. */ public XMPPTCPConnection(XMPPTCPConnectionConfiguration config) { super(config); this.config = config; addConnectionListener(new AbstractConnectionListener() { @Override public void connectionClosedOnError(Exception e) { if (e instanceof XMPPException.StreamErrorException || e instanceof StreamManagementException) { dropSmState(); } } }); }
@Override public void start() { synchronized (this.lifecycleMonitor) { if (this.running) { return; } XMPPTCPConnection connection = getConnection(); try { connection.connect(); connection.addConnectionListener(new LoggingConnectionListener()); Roster roster = Roster.getInstanceFor(connection); if (this.subscriptionMode != null) { roster.setSubscriptionMode(this.subscriptionMode); } else { roster.setRosterLoadedAtLogin(false); } connection.login(); this.running = true; } catch (Exception e) { throw new BeanInitializationException("failed to connect to XMPP service for " + connection.getXMPPServiceDomain(), e); } } }
private void connectToServer() { try { LOG.debug("Attempting vanilla XMPP Connection to {}:{}", xmppServer, xmppPort); xmpp.connect(); if (xmpp.isConnected()) { LOG.debug("XMPP Manager successfully connected"); // Following requires a later version of the library if (xmpp.isSecureConnection()) LOG.debug("XMPP Manager successfully negotiated a secure connection"); if (xmpp.isUsingTLS()) LOG.debug("XMPP Manager successfully negotiated a TLS connection"); LOG.debug("XMPP Manager Connected"); login(); // Add connection listener xmpp.addConnectionListener(conlistener); } else { LOG.debug("XMPP Manager Not Connected"); } } catch (Throwable e) { LOG.error("XMPP Manager unable to connect", e); } }
mConnection.addConnectionListener(this); PingManager pingManager = PingManager.getInstanceFor(mConnection); pingManager.registerPingFailedListener(this);
public void start() { synchronized (this.lifecycleMonitor) { if (this.running) { return; } try { this.connection.connect(); this.connection.addConnectionListener(new LoggingConnectionListener()); this.connection.login(); if (this.subscriptionMode != null) { Roster.getInstanceFor(this.connection).setSubscriptionMode(this.subscriptionMode); } this.running = true; } catch (Exception e) { throw new BeanInitializationException("failed to connect to XMPP service for " + this.connection.getServiceName(), e); } } }
private XMPPTCPConnection connect(long senderId, String apiKey) throws XMPPException, IOException, SmackException { ConnectionConfiguration config = new ConnectionConfiguration(GCM_SERVER, GCM_PORT); config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); config.setReconnectionAllowed(true); config.setRosterLoadedAtLogin(false); config.setSendPresence(false); config.setSocketFactory(SSLSocketFactory.getDefault()); XMPPTCPConnection connection = new XMPPTCPConnection(config); connection.connect(); connection.addConnectionListener(new LoggingConnectionListener()); connection.addPacketListener(this, new PacketTypeFilter(Message.class)); connection.login(senderId + "@gcm.googleapis.com", apiKey); return connection; }
xmppConn.addConnectionListener(this);