Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use smack with Openfire

Hi I am planning to develop a chat client which can connect to gtalk facebook etc...I have decided to use the smack API along with openfire..

But I need little guidance as to how to use it with openfire server..

And does the openfire provide a basic UI like log in box chat window etc...

I need to know how to plug or use smack with openfire

Thanks:)

like image 244
newbie Avatar asked May 11 '11 09:05

newbie


4 Answers

Configure openfire then refer to documentation provided by Smack. It has easy to understand examples. FYI openfire works fine with gtalk but with facebook it is very slow.


Sample code:-

ConnectionConfiguration config = new ConnectionConfiguration(host, 5222);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login(user_name, password);

Here host is the ip/domain name where openfire is configured.

like image 191
Harry Joy Avatar answered Oct 05 '22 23:10

Harry Joy


I have decided to use the smack API along with openfire.. But I need little guidance as to how to use it with openfire server..

What about Smack API Getting Started?

And does the openfire provide a basic UI like log in box chat window etc...

OpenFire is just the Server. To actually chat, you'll need some Jabber/XMPP Client. You could use Spark for tests.

like image 32
Tim Büthe Avatar answered Oct 05 '22 21:10

Tim Büthe


This is a sample, which will help set the status message on gtalk.

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Presence;

public class SmackToGtalk {
public static void main(String[] args) 
{
    ConnectionConfiguration config = new ConnectionConfiguration(
            "talk.google.com", 5222, "google.com");
    XMPPConnection connection = new XMPPConnection(config);
    Presence presence;
    String status;

    try {
        connection.connect();
        connection.login("[email protected]", "password");
        status = "DND";

        presence = new Presence(Presence.Type.available, status, 24,
                Presence.Mode.available);
        while (true) {
            status = set(status);
            presence.setStatus(status);
            connection.sendPacket(presence);
            Thread.sleep(1000);
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        connection.disconnect();
    }
}

private static String set(String input) {
    return input.substring(1) + input.charAt(0);
}
}
like image 44
frewper Avatar answered Oct 05 '22 23:10

frewper


In JSP / Java, import the smack.jar

<%@ page import="org.jivesoftware.smack.*;" %>

Place smack.jar in

tomcat/lib 

or yourwebapp/WEB-INF/lib

like image 26
deepakssn Avatar answered Oct 05 '22 21:10

deepakssn