Saturday 4 April 2015

Connecting to XMPP IM with Smack for Java applications

We will connect to openfire server using smack api

package com.javaproficiency.demo;

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

public class SmackDemo {
    public static void main(String[] args) {
          SmackDemo smackDemo=new  SmackDemo();

          XMPPConnection connection=smackDemo.XMPPConnection();




        
          System.out.println("Connecting to="+connection.getHost()+"  Post:"+connection.getPort());
    }

    public XMPPConnection XMPPConnection() {
        ConnectionConfiguration config = new ConnectionConfiguration(
                "host", "port");

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

No comments:

Post a Comment