Java Code Examples for org.jivesoftware.smack.tcp.XMPPTCPConnection#connect()

The following examples show how to use org.jivesoftware.smack.tcp.XMPPTCPConnection#connect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmppTools.java    From Smack with Apache License 2.0 6 votes vote down vote up
public static boolean createAccount(DomainBareJid xmppDomain, Localpart username, String password)
        throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException,
        InterruptedException {
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
            .setXmppDomain(xmppDomain);
    TLSUtils.acceptAllCertificates(configBuilder);
    XMPPTCPConnectionConfiguration config = configBuilder.build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    try {
        if (!supportsIbr(connection))
            return false;

        AccountManager accountManager = AccountManager.getInstance(connection);
        accountManager.createAccount(username, password);
        return true;
    } finally {
        connection.disconnect();
    }
}
 
Example 2
Source File: SmackIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@BeforeClass
public static void setup() throws IOException, InterruptedException, XMPPException, SmackException {

    XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
            .setUsernameAndPassword("baeldung","baeldung")
            .setXmppDomain("jabb3r.org")
            .setHost("jabb3r.org")
            .build();

    XMPPTCPConnectionConfiguration config2 = XMPPTCPConnectionConfiguration.builder()
            .setUsernameAndPassword("baeldung2","baeldung2")
            .setXmppDomain("jabb3r.org")
            .setHost("jabb3r.org")
            .build();

    connection = new XMPPTCPConnection(config);
    connection.connect();
    connection.login();

}
 
Example 3
Source File: SmackGcmSenderChannel.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
/**
 * Connects to GCM Cloud Connection Server using the supplied credentials.
 *
 * @param senderId
 *            Your GCM project number
 * @param apiKey
 *            API Key of your project
 */
protected void connect(long senderId, String apiKey, int keepAliveInterval) throws XMPPException, IOException, SmackException {

    // Configure connection
    ConnectionConfiguration config = new ConnectionConfiguration(GcmServiceConstants.GCM_SERVER, GcmServiceConstants.GCM_PORT);
    config.setSecurityMode(SecurityMode.enabled);
    config.setReconnectionAllowed(true);
    config.setRosterLoadedAtLogin(false);
    config.setSendPresence(false);
    config.setSocketFactory(SSLSocketFactory.getDefault());

    // Create connection object and initiate connection
    connection = new XMPPTCPConnection(config);
    pingManager = PingManager.getInstanceFor(connection);
    pingManager.setPingInterval(keepAliveInterval);
    pingManager.registerPingFailedListener(this);
    connection.connect();

    // Register listener to log connection state events
    connection.addConnectionListener(new SmackLoggingConnectionListener());

    // Handle incoming messages (delivery receipts and Google control messages)
    connection.addPacketListener(upstreamListener, new PacketTypeFilter(Message.class));

    // Log in...
    connection.login(senderId + "@" + GcmServiceConstants.GCM_SERVER, apiKey);
}
 
Example 4
Source File: XmppTools.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static boolean supportsIbr(DomainBareJid xmppDomain) throws SmackException, IOException, XMPPException,
        InterruptedException, KeyManagementException, NoSuchAlgorithmException {
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder()
            .setXmppDomain(xmppDomain);
    TLSUtils.acceptAllCertificates(configBuilder);
    XMPPTCPConnectionConfiguration config = configBuilder.build();
    XMPPTCPConnection connection = new XMPPTCPConnection(config);
    connection.connect();
    try {
        return supportsIbr(connection);
    } finally {
        connection.disconnect();
    }
}
 
Example 5
Source File: SmackConnection.java    From SmackAndroidDemo with Apache License 2.0 3 votes vote down vote up
public void connect() throws IOException, XMPPException, SmackException {
    Log.i(TAG, "connect()");

    XMPPTCPConnectionConfiguration.XMPPTCPConnectionConfigurationBuilder builder = XMPPTCPConnectionConfiguration.builder();
    builder.setServiceName(mServiceName);
    builder.setResource("SmackAndroidTestClient");
    builder.setUsernameAndPassword(mUsername, mPassword);
    builder.setRosterLoadedAtLogin(true);


    mConnection = new XMPPTCPConnection(builder.build());

    //Set ConnectionListener here to catch initial connect();
    mConnection.addConnectionListener(this);

    mConnection.connect();
    mConnection.login();

    PingManager.setDefaultPingInterval(600); //Ping every 10 minutes
    PingManager pingManager = PingManager.getInstanceFor(mConnection);
    pingManager.registerPingFailedListener(this);

    setupSendMessageReceiver();

    ChatManager.getInstanceFor(mConnection).addChatListener(this);
    mConnection.getRoster().addRosterListener(this);

}