第一步
官网下载smack.jar包
下载地址:http://www.igniterealtime.org/downloads/index.jsp#smack
第二步
把smack里边的jar导入你新建的java项目中
开始编写smack连接openfire代码
package openfireTest;
import org.jivesoftware.smack.AccountManager;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
public class SmackXMPTest {
private Connection connection;
private ConnectionConfiguration config;
//openfire 连接地址
private final static String server = "127.0.0.1";
public final void fail(Object o,Object... args){
if(o!=null&&args!=null&&args.length>0){
String s = o.toString();
for(int i=0;i<args.length;i++){
String item = args[i] == null ?"":args[i].toString();
s +="" + item;
}
System.out.println(s);
}
}
/**
* 初始化连接
*/
public void init(){
//第一个参数openfire地址,第二个参数端口号
config = new ConnectionConfiguration(server, 5222);
connection = new XMPPConnection(config);
try {
connection.connect();
//连接成功
} catch (XMPPException e) {
//连接失败
e.printStackTrace();
}
}
//测试登陆
public void testLogin(){
try {
connection.login("zhao\\40china.com", "1");
//登陆成功
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void destory(){
if(connection != null){
connection.disconnect();
connection = null;
}
}
public static void main(String[] args) {
SmackXMPTest test = new SmackXMPTest();
test.init();
test.testLogin();
}
}
分享到:
相关推荐
不错的OpenFire入门配置,从下载到配置。
让人快速上手openfire插件的开发,让你节省更多时间了解源码。
即时通讯Im Demo,用openfire做服务器,C#agsXmpp做客户端连接实现即时通讯。只实现登陆,接收发送消息。
openfire开发文档[汇编].pdf
Openfire插件开发人员指南
Openfire安装指南、 Openfire(Wildfire),一款基于GPL协议开源软件,Openfire有linux、windows和MAC的不同版本,软件需要java环境支持,不过软件本身自带了环境包,你可以根据你的需要下载不同的版本。
openfire插件开发指南,官网原版翻译,对插件开发有一定的帮助,不错的资源。
openfire搭建本地开发环境所需jar。 包含:coherence.jar、coherence-work.jar、tangosol.jar、bouncycastle.jar
这是一个文档,内容是如何编写Openfire开发插件、部署源码
Openfire二次开发问题分析及解决资料,列举了二次开发过程中可能会遇到的问题及解决的把办法。
目的:主要是为了监控Openfire各类message,然后对message body做进一步...局限:因为时间有限,本插件并没有对Openfire message协议进行扩展,都是基于原生的xml协议,因此后续开发还需要进行更加深入的二次开发操作。
openfire webchat开发包!
spark+openfire二次开发,包括配置基本插件实现等等
openfire即时通讯开发文档,包括如何部署,以及代码的讲解
libjingle0.6.14连接openfire
OpenFire二次开发环境搭建
XMPP 协议讲解 openfire 结构分析以及插件开发指南 希望能帮到想学习openfire的同学
Openfire调试、编译开发环境与安装
openfire编译、openfire打包、openfire开发、openfire插件开发、openfire原理说明等,全是好东东