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

newbie
  • 80
  • 1
  • 1
  • 7
  • 1
    Was browsing the net and came across this link that may be of use:

    [Instant Messaging Infrastructure](http://www.javacodegeeks.com/2010/08/instant-messaging-infrastructure.html)
    – EthiopionZA Dec 19 '12 at 15:03

4 Answers4

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.

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
  • 1
    @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... – newbie May 11 '11 at 09:45
  • @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. – Harry Joy May 11 '11 at 09:56
  • So where so I code for it??In eclipse..should I configure openfire in eclipse?? – newbie May 11 '11 at 09:58
  • @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. – Harry Joy May 11 '11 at 10:03
  • So how does the openfire understand ??I mean I don see any set up or configuration..So how does the openfire know?? – newbie May 11 '11 at 10:07
  • @kuber: We are providing ip and port on which openfire is running. – Harry Joy May 11 '11 at 10:08
  • hi any tell me wat is the host here – kannappan Jun 22 '11 at 06:18
  • @Kannappan: host is the ip or domain name of the machine where openfire is running. – Harry Joy Jun 22 '11 at 06:19
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("mail_id@gmail.com", "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);
}
}
frewper
  • 1,385
  • 6
  • 18
  • 44
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.

Robin
  • 24,062
  • 5
  • 49
  • 58
Tim Büthe
  • 62,884
  • 17
  • 92
  • 129
  • @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 step – newbie May 11 '11 at 09:43
  • Sure, you set up the server like described here: http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/install-guide.html. Thereafter you can connect with some client or the smack API. – Tim Büthe May 11 '11 at 09:46
  • @Tim I have set up the openfire...I am askin how do I connect it with the smack API?? – newbie May 11 '11 at 09:48
  • Do you have started? Post some source code along with the Exception you're getting... – Tim Büthe May 11 '11 at 09:51
  • @Tim...No what I meant was should I upload the jar files under plugins in openfire??? – newbie May 11 '11 at 09:54
  • 1
    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: http://en.wikipedia.org/wiki/Extensible_Messaging_and_Presence_Protocol. 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. – Tim Büthe May 11 '11 at 10:19
1

In JSP / Java, import the smack.jar

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

Place smack.jar in

tomcat/lib 

or yourwebapp/WEB-INF/lib

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
deepakssn
  • 5,195
  • 2
  • 24
  • 19