簡體   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