How to use smack with Openfire
Asked Answered
R

4

6

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:)

Rone answered 11/5, 2011 at 9:37 Comment(1)
Was browsing the net and came across this link that may be of use: <br/><br/> Instant Messaging InfrastructureRozina
L
3

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.

Liuka answered 11/5, 2011 at 9:40 Comment(6)
@Tim-It does not tell how I am supposed t it with openfire...Like should I plug in the smack or is there a different stepRone
Sure, you set up the server like described here: igniterealtime.org/builds/openfire/docs/latest/documentation/…. Thereafter you can connect with some client or the smack API.Pragmaticism
@Tim I have set up the openfire...I am askin how do I connect it with the smack API??Rone
Do you have started? Post some source code along with the Exception you're getting...Pragmaticism
@Tim...No what I meant was should I upload the jar files under plugins in openfire???Rone
I think you haven't understood the whole thing. You need some server that understand the XMPP-Protocol. In youe case that is OpenFire, GTalk or something else. When a client connects, it sends XMPP messages as described in the protocol, see Wikipedia: en.wikipedia.org/wiki/…. So far so good, to implement a client, you could use the smack API. With this API you use Java to construct and send the XMPP messages mentioned above. So in a nutshell: The Smack API is no OpenFire Plugin and not needed on the server. You just use it to build a client.Pragmaticism
R
4

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.

Resiniferous answered 11/5, 2011 at 9:43 Comment(8)
@Harry-I have gone through the documentation but I dint see anywhere as to how to use smack with openfire...I have the openfire configured...Rone
@Kuber: to just simply use opefire with smack. No extra jar file is needed. But to work with gtalk/facebook you will requires plugins in openfire.Resiniferous
So where so I code for it??In eclipse..should I configure openfire in eclipse??Rone
@Kuber: no need to configure openfire in eclipse. Download SMACK jars. Then just create a java file copy/paste above code. replace username/host/password. Run the file.Resiniferous
So how does the openfire understand ??I mean I don see any set up or configuration..So how does the openfire know??Rone
@kuber: We are providing ip and port on which openfire is running.Resiniferous
hi any tell me wat is the host hereBikales
@Kannappan: host is the ip or domain name of the machine where openfire is running.Resiniferous
L
3

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.

Liuka answered 11/5, 2011 at 9:40 Comment(6)
@Tim-It does not tell how I am supposed t it with openfire...Like should I plug in the smack or is there a different stepRone
Sure, you set up the server like described here: igniterealtime.org/builds/openfire/docs/latest/documentation/…. Thereafter you can connect with some client or the smack API.Pragmaticism
@Tim I have set up the openfire...I am askin how do I connect it with the smack API??Rone
Do you have started? Post some source code along with the Exception you're getting...Pragmaticism
@Tim...No what I meant was should I upload the jar files under plugins in openfire???Rone
I think you haven't understood the whole thing. You need some server that understand the XMPP-Protocol. In youe case that is OpenFire, GTalk or something else. When a client connects, it sends XMPP messages as described in the protocol, see Wikipedia: en.wikipedia.org/wiki/…. So far so good, to implement a client, you could use the smack API. With this API you use Java to construct and send the XMPP messages mentioned above. So in a nutshell: The Smack API is no OpenFire Plugin and not needed on the server. You just use it to build a client.Pragmaticism
I
3

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);
}
}
Inarticulate answered 7/8, 2012 at 8:48 Comment(0)
G
1

In JSP / Java, import the smack.jar

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

Place smack.jar in

tomcat/lib 

or yourwebapp/WEB-INF/lib

Grenadines answered 23/5, 2012 at 3:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.