繁体   English   中英

如何使用Openfire打击

[英]How to use smack with Openfire

嗨,我打算开发一个聊天客户端,可以连接到gtalk facebook等...我决定使用smack API和openfire ..

但是我对如何在openfire服务器上使用它几乎没有什么指导。

openfire是否提供基本的用户界面,如登录框聊天窗口等...

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

谢谢:)

配置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 / domain名称。

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

我决定使用smack API以及openfire ..但是我对如何在openfire服务器上使用它几乎没有什么指导..

Smack API入门怎么样?

openfire是否提供基本的用户界面,如登录框聊天窗口等...

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

在JSP / Java中,导入smack.jar

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

把smack.jar放入

tomcat/lib 

或yourwebapp / WEB-INF / lib

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM