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

The following examples show how to use org.jivesoftware.smack.tcp.XMPPTCPConnection#login() . 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: 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 2
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 3
Source File: XMPP.java    From XMPPSample_Studio with Apache License 2.0 5 votes vote down vote up
public void login(String user, String pass, StatusItem status, String username)
            throws XMPPException, SmackException, IOException, InterruptedException {
        Log.i(TAG, "inside XMPP getlogin Method");
        long l = System.currentTimeMillis();
        XMPPTCPConnection connect = connect();
        if (connect.isAuthenticated()) {
            Log.i(TAG, "User already logged in");
            return;
        }

        Log.i(TAG, "Time taken to connect: " + (System.currentTimeMillis() - l));

        l = System.currentTimeMillis();
        connect.login(user, pass);
        Log.i(TAG, "Time taken to login: " + (System.currentTimeMillis() - l));

        Log.i(TAG, "login step passed");

        Presence p = new Presence(Presence.Type.available);
        p.setMode(Presence.Mode.available);
        p.setPriority(24);
        p.setFrom(connect.getUser());
        if (status != null) {
            p.setStatus(status.toJSON());
        } else {
            p.setStatus(new StatusItem().toJSON());
        }
//        p.setTo("");
        VCard ownVCard = new VCard();
        ownVCard.load(connect);
        ownVCard.setNickName(username);
        ownVCard.save(connect);

        PingManager pingManager = PingManager.getInstanceFor(connect);
        pingManager.setPingInterval(150000);
        connect.sendPacket(p);


    }
 
Example 4
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);

}