share

Saturday, 4 April 2015

Login to XMPP IM with Smack for Java applications

Maven dependency

<dependency>
            <groupId>jivesoftware</groupId>
            <artifactId>smack</artifactId>
            <version>3.1.0</version>
 </dependency>
<dependency>
            <groupId>jivesoftware</groupId>
            <artifactId>smackx</artifactId>
            <version>3.1.0</version>
   </dependency>


package com.javaproficiency.demo;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;

public class LoginSmack {
          public static void main(String[] args) {
              LoginSmack loginSmack=new LoginSmack();
            XMPPConnection connection=loginSmack.Connect();
          
            try {
                connection.login("Username","Password");
            } catch (XMPPException e) {
               
                e.printStackTrace();
            }
            System.out.println("Login Successfully");
        }
         
          /**
           *
           * @return XMPP Connection
           */
         
          public XMPPConnection Connect() {
             
              ConnectionConfiguration config = new ConnectionConfiguration(
                      "localhost", 5222);

              /*
               * ConnectionConfiguration config = new ConnectionConfiguration(
               * "192.163.2.200", 5222);
               */
              XMPPConnection connection = new XMPPConnection(config);
              try {
                  connection.connect();
              } catch (XMPPException e) {
             
                  e.printStackTrace();
              }
              return connection;
          }
         
      
}

1 comment:

  1. The first time I saw this website, I was immediately attracted to zoom. Moreover, all the information is in my opinion quite interesting and intriguing. I hope you also visit my website and pass judgment on my website. Thanks.
    XMPP

    ReplyDelete