关于判断openfire 服务器中用户的在线状态问题
2014-12-11 16:36
288 查看
虽然接触了openfire有段时间了,但还是没有深入去理解其原理,所以,遇到一些新问题就有点束手无策,今天又遇到一个,开始以为用户的在线状态会存数据库里面呢,没想到openfire没这么干,存在了session里面,找了很多资料,终于找到了方法,好像也还很简单的。废话不多说,进入正题:
首先我们要确保openfire 服务器中安装了presence 插件,同时在openfire后台中的服务器设置中进入Presence Service处,设置任何人都可以访问的权限(不过这样设置的话会对安全性有一定影响)。
然后就是代码判断了:
//传入路径格式: String url = "http://localhost:9090/plugins/presence/status?jid=admin@meson.com&type=xml";
public static int IsUserOnLine(String strUrl) {
int state = 0;
//返回值 : 0 - 用户不存在; 1 - 用户在线; 2 - 用户离线
try {
URL oUrl = new URL(strUrl);
URLConnection oConn = oUrl.openConnection();
if (oConn != null) {
BufferedReader oIn = new BufferedReader(new InputStreamReader(oConn.getInputStream()));
if (null != oIn) {
String strFlag = oIn.readLine();
//System.out.println(strFlag);
oIn.close();
if (strFlag.indexOf("type=\"unavailable\"") >= 0) {
state = 2;
}
if (strFlag.indexOf("type=\"error\"") >= 0) {
state = 0;
} else if (strFlag.indexOf("priority") >= 0 || strFlag.indexOf("id=\"") >= 0) {
state = 1;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return state;
} //这是网上copy的代码
首先我们要确保openfire 服务器中安装了presence 插件,同时在openfire后台中的服务器设置中进入Presence Service处,设置任何人都可以访问的权限(不过这样设置的话会对安全性有一定影响)。
然后就是代码判断了:
//传入路径格式: String url = "http://localhost:9090/plugins/presence/status?jid=admin@meson.com&type=xml";
public static int IsUserOnLine(String strUrl) {
int state = 0;
//返回值 : 0 - 用户不存在; 1 - 用户在线; 2 - 用户离线
try {
URL oUrl = new URL(strUrl);
URLConnection oConn = oUrl.openConnection();
if (oConn != null) {
BufferedReader oIn = new BufferedReader(new InputStreamReader(oConn.getInputStream()));
if (null != oIn) {
String strFlag = oIn.readLine();
//System.out.println(strFlag);
oIn.close();
if (strFlag.indexOf("type=\"unavailable\"") >= 0) {
state = 2;
}
if (strFlag.indexOf("type=\"error\"") >= 0) {
state = 0;
} else if (strFlag.indexOf("priority") >= 0 || strFlag.indexOf("id=\"") >= 0) {
state = 1;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return state;
} //这是网上copy的代码
相关文章推荐
- openfire服务端消息回执插件(接收方离线时的情况),判断用户的在线状态
- openfire服务端消息回执插件(接收方离线时的情况),判断用户的在线状态
- openfire服务端消息回执插件(接收方离线时的情况),判断用户的在线状态
- 判断用户的在线状态 onbeforeunload事件
- 关于xmpp连接openfire服务器的一些常见问题
- asp.net关于WEB端用户重复提交问题。禁用服务器控件按钮问题。
- openfire xmpp 通过presence service判断用户是否在线
- openfire xmpp 如何判断用户是否在线
- 关于服务器远程桌面选择用户连接的问题
- openfire xmpp 如何判断用户是否在线
- 判断openfire用户的状态
- 关于小球碰撞判断的一些问题··在线等
- 关于websocket集群中不同服务器的用户间通讯问题
- 关于openfire服务器启动变慢问题解决
- 限制用户登录/判断用户在线的问题
- asp.net关于WEB端用户重复提交问题。禁用服务器控件按钮问题。
- 关于用ActionContext类添加用户状态信息的问题
- WAMPSERVER-服务器离线无法切换到在线状态问题的解决