`
- 浏览:
1042560 次
- 性别:
- 来自:
长沙
-
-
public class IMServer {
-
-
private ConnectionConfiguration connectionConfig;
-
private XMPPConnection connection;
-
private Roster roster;
-
private boolean loginState;
-
private Listener listener;
-
-
-
-
public IMServer(String serviceName) {
-
connectionConfig = new ConnectionConfiguration(serviceName);
-
connection = new XMPPConnection(connectionConfig);
-
listener=new Listener();
-
try {
- connection.connect();
-
} catch (XMPPException e) {
- e.printStackTrace();
- }
- }
-
-
-
-
-
public IMServer(String host, String port) {
-
-
connectionConfig = new ConnectionConfiguration(host, Integer
- .parseInt(port));
-
connection = new XMPPConnection(connectionConfig);
-
listener=new Listener();
-
try {
- connection.connect();
-
} catch (XMPPException e) {
- e.printStackTrace();
- }
- }
-
-
-
-
-
public IMServer(String host, int port, String serviceName) {
-
connectionConfig = new ConnectionConfiguration(host, port, serviceName);
-
connection = new XMPPConnection(connectionConfig);
-
listener=new Listener();
-
-
try {
- connection.connect();
-
-
} catch (XMPPException e) {
- e.printStackTrace();
- }
- }
-
-
-
-
-
-
-
public boolean loginServer(String userName, String userPswd) {
-
try {
- connection.login(userName, userPswd);
-
loginState = true;
- roster = connection.getRoster();
-
- listener.regConnectionListener(connection);
- listener.regPackListener(connection);
- listener.onlineServer(connection);
- listener.regRosterListener(roster);
-
} catch (XMPPException e) {
- e.printStackTrace();
- }
-
return loginState;
- }
-
-
-
-
-
-
-
-
-
public boolean createAccount(String regUserName, String regUserPswd) {
-
try {
- connection.getAccountManager().createAccount(regUserName,
- regUserPswd);
-
return true;
-
} catch (XMPPException e) {
- e.printStackTrace();
-
return false;
- }
-
- }
-
-
-
-
-
-
-
public boolean logoutServer() {
-
if (loginState) {
- connection.disconnect();
- listener.stopOnlineThread();
-
loginState = false;
- }
-
return !loginState;
- }
-
-
-
-
-
-
-
public List<RosterEntry> getOnlineEntries() {
-
List<RosterEntry> EntriesList = new ArrayList<RosterEntry>();
- Collection<RosterEntry> rosterEntry = roster.getEntries();
- Iterator<RosterEntry> i = rosterEntry.iterator();
-
while (i.hasNext()){
-
- EntriesList.add(i.next());
- }
-
return EntriesList;
- }
-
-
-
-
-
-
public List<RosterEntry> getAllEntries() {
-
List<RosterEntry> EntriesList = new ArrayList<RosterEntry>();
- Collection<RosterEntry> rosterEntry = roster.getEntries();
- Iterator<RosterEntry> i = rosterEntry.iterator();
-
while (i.hasNext())
- EntriesList.add(i.next());
-
return EntriesList;
- }
-
-
-
-
-
-
-
public List<RosterEntry> getEntriesByGroup(String groupName) {
-
List<RosterEntry> EntriesList = new ArrayList<RosterEntry>();
- RosterGroup rosterGroup = roster.getGroup(groupName);
- Collection<RosterEntry> rosterEntry = rosterGroup.getEntries();
- Iterator<RosterEntry> i = rosterEntry.iterator();
-
while (i.hasNext())
- EntriesList.add(i.next());
-
return EntriesList;
- }
-
-
-
-
-
-
-
public List<RosterGroup> getGroups() {
-
List<RosterGroup> groupsList = new ArrayList<RosterGroup>();
- Collection<RosterGroup> rosterGroup = roster.getGroups();
- Iterator<RosterGroup> i = rosterGroup.iterator();
-
while (i.hasNext())
- groupsList.add(i.next());
-
return groupsList;
- }
-
-
-
-
-
public XMPPConnection getConnection() {
-
return connection;
- }
-
-
-
-
-
public boolean getLoginState() {
-
return loginState;
- }
-
-
-
-
-
public Roster getRoster() {
-
return roster;
- }
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
搭建openfire后,用 smack api 连接服务的测试demo。运行官网范例,发现其实不易,smack4.1.4中缺少很多依赖于第3方的jar包。不断debug甚是痛苦,终于跑起来了。分享出来给只是想要个初体验的同学。
Asmack是smack的android版,是对xmpp协议进行了封装,并提供了丰富的api,简化了操作。Openfire是一个开源的IM服务器,基于Xmpp实现。换句话说使用xmpp开发即时通讯应用的话,服务器端已经开发好了,就是openfire。
Smack是一个为使用XMPP服务器聊天和发送即时消息交流而提供的库。 Smack的主要优势: 使用简单且拥有强大的API。向用户发送一条文本消息只需用一下三行...本文档将向你介绍Smack API,并大概介绍几个重要的类和概念。
这个是Smack API的中文版,详细介绍了smack原理,并且有几个小例子在里面
smack API XMPP,openfire开发必备。
Smack-Openfire im with Android, include heartbeat and auto reconnect 图文详情地址: Smack是一个开源,易于使用的XMPP(jabber)客户端类库。优点:简单的,功能强大,给用户发送信息只需三行代码便可完成。...
smack api,xmpp协议的客户端开发
关于Smack编程库,前面我们提到,它是面向Java端的api,主要在PC上使用,利用它我们可以向openfire服务器注册用户,发送消息,并且可以通过监听器获得此用户的应答消息,以及构建聊天室,分组,个人通讯录等等。
找了好久,终于找到了smack中文版的api了
smack API XMPP,openfire开发必备,多多支持哦
Smack是即时通信客户端编程库,目前我已测通通过jsp使用smack的API向openfire注册用户发送消息,并且可以通过监听器获得此用户的应答消息。 通过smack向msn用户和QQ用户,gtalk用户发送消息应该也可以实现,关于向...
smark+openfire 构建即时通讯系统,本资源为smark的中文API
Smack主要是xmpp协议的实现,提供了一套很好的api,所以下面操作xmpp都是通过使用Smack的api来实现,从4.1.0开始,它就支持Android了,所以我们直接使用Smack即可,当然在这不支持之前是使用Asmack这个包的,里面...
资料中详细分析SMACK类库的指令,是IM即时通讯编程的开源api
具有Openfire和Smack Api的Java客户端屏幕内容它是使用Java编写的Smack API和Openfire服务器与Spark客户端进行通信的客户端。谢谢
使用openfire作为IM服务器,spark作为pc端,本实例作为安卓客户端进行聊天交流,注意本代码是安卓端,其他组件可以上相关网站下载,按照步骤搭建好环境之后,使用本...通过本代码,你可以学习如何使用smack库的api接口
Openfire Smack Spark实现Android端的即时通讯APP(仿微信)。 功能已基本实现完毕,本项目基于Smack 4.1.3,这个版本的smack有很大的改动,网上的Demo很少,基本都是查看API实现的.zip,太多无法一一验证是否可用,...
smack4.0.4的所有jar包和API文档
Openfire+Smack+Spark实现Android端的即时通讯APP(仿微信)。 功能已基本实现完毕,本项目基于Smack 4.1.3,这个版本的smack有很大的改动,网上的Demo很少,基本都是查看API实现的。
1. 提供最新的2014-6-20的asmack jar包。 2. 可以参考smack的API文档进行开发。 3. 只是简单地针对openfire服务器进行connect和Login,并下拉了局域网用户数据信息。 4. Demo待完善中……