How to use smack with openfire

Hi I plan to develop a chat client that can connect to gtalk facebook etc. I decided to use the smack API with openfire ..

But I do not need to be guided by how to use it with an openfire server.

And does openfire create a basic interface, such as a log window in a chat window, etc ...

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

Thanks:)

+6
source share
4 answers

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

How about getting started with the Smack API application ?

And does openfire do the basic UI, how to enter the chat window window, etc.

OpenFire is just a server. To chat, you will need a Jabber / XMPP client. You can use Spark for tests.

+3
source

Configure openfire, then refer to the documentation provided by Smack . This is easy to understand. FYI openfire works fine with gtalk, but with facebook it is very slow.


Code example: -

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 in which openfire is configured.

+4
source

This is a sample that will help set the status message to 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); } } 
+3
source

In JSP / Java, import smack.jar

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

Put smack.jar in

 tomcat/lib 

or yourwebapp / WEB-INF / Library

+1
source

Source: https://habr.com/ru/post/887808/


All Articles