How to use smack with Openfire
Solution 1
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.
Solution 2
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.
Solution 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);
}
}
Solution 4
In JSP / Java, import the smack.jar
<%@ page import="org.jivesoftware.smack.*;" %>
Place smack.jar in
tomcat/lib
or yourwebapp/WEB-INF/lib
newbie
Updated on June 16, 2022Comments
-
newbie about 2 years
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 about 13 years@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 about 13 years@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...
-
Tim Büthe about 13 yearsSure, 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.
-
newbie about 13 years@Tim I have set up the openfire...I am askin how do I connect it with the smack API??
-
Tim Büthe about 13 yearsDo you have started? Post some source code along with the Exception you're getting...
-
newbie about 13 years@Tim...No what I meant was should I upload the jar files under plugins in openfire???
-
Harry Joy about 13 years@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.
-
newbie about 13 yearsSo where so I code for it??In eclipse..should I configure openfire in eclipse??
-
Harry Joy about 13 years@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.
-
newbie about 13 yearsSo how does the openfire understand ??I mean I don see any set up or configuration..So how does the openfire know??
-
Harry Joy about 13 years@kuber: We are providing ip and port on which openfire is running.
-
Tim Büthe about 13 yearsI 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.
-
kannappan about 13 yearshi any tell me wat is the host here
-
Harry Joy about 13 years@Kannappan: host is the ip or domain name of the machine where openfire is running.