首页 Openfire即时通讯服务搭建与Smack访问

Openfire即时通讯服务搭建与Smack访问

举报
开通vip

Openfire即时通讯服务搭建与Smack访问openfire即时通讯服务搭建与Smack访问 Openfire 是开源的、基于可拓展通讯和表示协议(XMPP)、采用Java编程语言开发的实时协作服务器。 Openfire安装和使用都非常简单,并利用Web进行管理。单台服务器可支持上万并发用户。 首先到openfire官网上去下载Openfire的服务器包与Smack的客户端调用包。 Openfire下载后,如果是win的版本,那么它是一个exe的安装包,运行下一步下一步即可,其间会需要配置数据库(Openfire当然是需要数据库支持的了,比如要存帐号等...

Openfire即时通讯服务搭建与Smack访问
openfire即时通讯服务搭建与Smack访问 Openfire 是开源的、基于可拓展通讯和表示协议(XMPP)、采用Java编程语言开发的实时协作服务器。 Openfire安装和使用都非常简单,并利用Web进行管理。单台服务器可支持上万并发用户。 首先到openfire官网上去下载Openfire的服务器包与Smack的客户端调用包。 Openfire下载后,如果是win的版本,那么它是一个exe的安装包,运行下一步下一步即可,其间会需要配置数据库(Openfire当然是需要数据库支持的了,比如要存帐号等等的信息)。 编写我们的程序访问Operfire [java] view plain copy import java.util.Collection;  import java.util.Iterator;  import javax.net.SocketFactory;  import org.jivesoftware.smack.AccountManager;  import org.jivesoftware.smack.Chat;  import org.jivesoftware.smack.ChatManager;  import org.jivesoftware.smack.ChatManagerListener;  import org.jivesoftware.smack.Connection;  import org.jivesoftware.smack.ConnectionConfiguration;  import org.jivesoftware.smack.MessageListener;  import org.jivesoftware.smack.Roster;  import org.jivesoftware.smack.RosterEntry;  import org.jivesoftware.smack.XMPPConnection;  import org.jivesoftware.smack.XMPPException;  import org.jivesoftware.smack.packet.Message;  import org.jivesoftware.smack.packet.Presence;  import org.jivesoftware.smack.packet.Session;  import org.jivesoftware.smack.packet.Message.Type;  public class SmackUtil {  private Connection connection;  private ConnectionConfiguration config;  /** openfire服务器address */  private final static String server = "10.100.53.65";  private final void print(Object o) {  if (o != null) {  System.out.println(o);  }  }  private final void print(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();  if (s.contains("{" + i + "}")) {  s = s.replace("{" + i + "}", item);  } else {  s += " " + item;  }  }  System.out.println(s);  }  }  /** * 初始Smack对openfire服务器链接的基本配置 */  public void init() {  try {  //connection = new XMPPConnection(server);  //connection.connect();  /** 5222是openfire服务器默认的通信端口,你可以登录:9090/到管理员控制台查看客户端到服务器端口 */  config = new ConnectionConfiguration(server, 5222);  /** 是否启用压缩 */  config.setCompressionEnabled(true);  /** 是否启用安全验证 */  config.setSASLAuthenticationEnabled(true);  /** 是否启用调试 */  config.setDebuggerEnabled(false);  config.setReconnectionAllowed(true);  config.setRosterLoadedAtLogin(true);  /** 创建connection链接 */  connection = new XMPPConnection(config);  /** 建立连接 */  connection.connect();  System.out.println("connection success");  } catch (XMPPException e) {  e.printStackTrace();  }  print(connection);  print(connection.getConnectionID());  }  public void destory() {  if (connection != null) {  connection.disconnect();  connection = null;  }  }  /** * ConnectionConfiguration 的基本配置相关信息 */  public void seeConfig() {  print("PKCS11Library: " + config.getPKCS11Library());  print("ServiceName: {0}", config.getServiceName());  // ssl证书密码  print("TruststorePassword: {0}", config.getTruststorePassword());  print("TruststorePath: {0}", config.getTruststorePath());  print("TruststoreType: {0}", config.getTruststoreType());  SocketFactory socketFactory = config.getSocketFactory();  print("SocketFactory: {0}", socketFactory);  }  /** * Connection 基本方法信息 */  public void seeConnection() {  /** 用户管理 */  AccountManager accountManager = connection.getAccountManager();  for (String attr : accountManager.getAccountAttributes()) {  print("AccountAttribute: {0}", attr); 
本文档为【Openfire即时通讯服务搭建与Smack访问】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_477730
暂无简介~
格式:doc
大小:25KB
软件:Word
页数:8
分类:互联网
上传时间:2019-02-08
浏览量:13