如何在 Openfire 中使用 smack

发布于 2024-11-06 13:37:19 字数 224 浏览 8 评论 0原文

你好 我计划开发一个可以连接到 gtalk facebook 等的聊天客户端...我决定将 smack API 与 openfire 一起使用..

但是我需要很少的指导来了解如何将它与 openfire 服务器一起使用..

并且openfire 提供了一个基本的 UI,比如登录框聊天窗口等...

我需要知道如何使用 openfire 插入或使用 smack

谢谢:)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情丝乱 2024-11-13 13:37:19

配置 openfire 然后参考 Smack 提供的文档。它有易于理解的示例。仅供参考,openfire 与 gtalk 配合使用效果很好,但与 facebook 配合使用时速度非常慢。


示例代码:-

ConnectionConfiguration config = new ConnectionConfiguration(host, 5222);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login(user_name, password);

这里的host是配置openfire的ip/域名。

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.

无人接听 2024-11-13 13:37:19

我决定将 smack API 与 openfire 一起使用..
但我几乎不需要指导如何
与 openfire 服务器一起使用..

Smack API 入门< /a>?

openfire 是否提供了基本的
UI如登录框聊天窗口等...

OpenFire 只是服务器。要真正聊天,您需要一些 Jabber/XMPP 客户端。您可以使用 Spark 进行测试。

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.

萌辣 2024-11-13 13:37:19

这是一个示例,它将帮助设置 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);
}
}

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);
}
}
围归者 2024-11-13 13:37:19

在 JSP/Java 中,导入 smack.jar

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

将 smack.jar 放入

tomcat/lib 


yourwebapp/WEB-INF/lib

In JSP / Java, import the smack.jar

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

Place smack.jar in

tomcat/lib 

or
yourwebapp/WEB-INF/lib

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文