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:)
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.
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.
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);
}
}
In JSP / Java, import the smack.jar
<%@ page import="org.jivesoftware.smack.*;" %>
Place smack.jar in
tomcat/lib
or yourwebapp/WEB-INF/lib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With