java 如何在 Openfire 中使用 smack
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5962140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use smack with Openfire
提问by newbie
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..
嗨,我正计划开发一个可以连接到 gtalk facebook 等的聊天客户端……我决定将 smack API 与 openfire 一起使用。
But I need little guidance as to how to use it with openfire server..
但是我几乎不需要关于如何在 openfire 服务器上使用它的指导。
And does the openfire provide a basic UI like log in box chat window etc...
并且 openfire 是否提供了一个基本的用户界面,比如登录框聊天窗口等......
I need to know how to plug or use smack with openfire
我需要知道如何在 openfire 中插入或使用 smack
Thanks:)
谢谢:)
采纳答案by Tim Büthe
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..
我决定将 smack API 与 openfire 一起使用。
What about Smack API Getting Started?
Smack API 入门怎么样?
And does the openfire provide a basic UI like log in box chat window etc...
并且 openfire 是否提供了一个基本的用户界面,比如登录框聊天窗口等......
OpenFire is just the Server. To actually chat, you'll need some Jabber/XMPP Client. You could use Sparkfor tests.
OpenFire 只是服务器。要真正聊天,您需要一些 Jabber/XMPP 客户端。您可以使用Spark进行测试。
回答by Harry Joy
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.
配置 openfire 然后参考Smack 提供的文档。它有易于理解的示例。仅供参考,openfire 在 gtalk 上运行良好,但在 facebook 上运行速度很慢。
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.
这里的host是配置openfire的ip/域名。
回答by frewper
This is a sample, which will help set the status message on gtalk.
这是一个示例,将有助于在 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);
}
}
回答by deepakssn
In JSP / Java, import the smack.jar
在 JSP/Java 中,导入 smack.jar
<%@ page import="org.jivesoftware.smack.*;" %>
Place smack.jar in
将 smack.jar 放入
tomcat/lib
or yourwebapp/WEB-INF/lib
或 yourwebapp/WEB-INF/lib