openfire xmpp 如何判断用户是否在线

2023-05-16

http://iammr.7.blog.163.com/blog/static/49102699201041961613109/


想象中如此简单的功能,想不到却这般大费周折。
如要实现,必须先确保:
1. openfire中安装有“Presence” 插件。

 
2. 确保该插件设置可允许任何人访问(如果是跨域浏览的话)
 

然后通过如下方式访问: http://www.igniterealtime.org/projects/openfire/plugins/presence/readme.html

访问结果如下:
 账号 状态 xmltext 
 user1 不存在 <presence type="error" from="user1@my.openfire.com"><error code="403" type="auth"><forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></presence> null
 user2 离线 <presence type="unavailable" from="user2@my.openfire.com"><status>Unavailable</status></presence> Unavailable
 user8 在线 <presence from="user8@my.openfire.com/trm"><priority>0</priority></presence>
或者
<presence id="6Mgiu-13" from="user8@my.openfire.com/Smack"/>
 null
   
java代码:
import java.net.*;
import java.io.*;

/**
 * 判断openfire用户的状态
 *     strUrl : url格式 - http://my.openfire.com:9090/plugins/presence/status?jid=user1@my.openfire.com&type=xml
 *    返回值 : 0 - 用户不存在; 1 - 用户在线; 2 - 用户离线
 *  说明   :必须要求 openfire加载 presence 插件,同时设置任何人都可以访问
 */    
public  static short IsUserOnLine(String strUrl)
{
    short            shOnLineState    = 0;    //-不存在-
    
    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();
            oIn.close();
            
            if(strFlag.indexOf("type=\"unavailable\"")>=0)
            {
                shOnLineState = 2;
            }
            if(strFlag.indexOf("type=\"error\"")>=0)
            {
                shOnLineState = 0;
            }
            else if(strFlag.indexOf("priority")>=0 || strFlag.indexOf("id=\"")>=0)
            {
                shOnLineState = 1;
            }
        }
    }
    }
    catch(Exception e)
    {            
    }
    
    return     shOnLineState;
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

openfire xmpp 如何判断用户是否在线 的相关文章

随机推荐

  • PHP 做守护进程

    http www 21andy com blog 20100228 1728 html Unix中 nohup 命令功能就是不挂断地运行命令 xff0c 同时 nohup 把程序的所有输出到放到当前目录 nohup out 文件中 xff0
  • php中获取http请求的代码

    获取http的请求 public function get http raw raw 61 39 39 1 请求行 raw 61 SERVER 39 REQUEST METHOD 39 39 39 SERVER 39 REQUEST URI
  • 应用向左,理论向右,计算机2021的冰火两重天

    近来来计算理论的发展极其缓慢 xff0c 而与之对应的是计算机领域的应用侧发展可谓日新月异 xff0c 像GPT 3及其衍生的AI模型 xff0c 各类大数据模型 超大规模云平台等等方面的进展不胜枚举 xff0c 相关成果也都举世瞩目 xf
  • mysqldump常用命令

    http www blogjava net Alpha archive 2007 08 10 135694 html 1 导出整个数据库 mysqldump u 用户名 p 数据库名 gt 导出的文件名 mysqldump u wcnc p
  • ci中使用多个数据库的方法

    config 39 hostname 39 61 config item 39 database ip 39 config 39 username 39 61 config item 39 database username 39 conf
  • php中强制浏览器下载文件

    file 61 fopen written file 39 r 39 header 39 Content type application octet stream 39 header 39 Accept Ranges bytes 39 h
  • PHP 守护进程类

    出处 xff1a http www oschina net code snippet 239150 11088 用 PHP 实现的 Daemon 类 可以在服务器上实现队列或者脱离 crontab 的计划任务 使用的时候 xff0c 继承于
  • linux的nohup命令的用法

    http www cnblogs com allenblogs archive 2011 05 19 2051136 html 在应用Unix Linux时 xff0c 我们一般想让某个程序在后台运行 xff0c 于是我们将常会用 amp
  • Mysql中创建用户帐户的方法

    http www eygle com digest 2008 01 mysql create user html 1 CREATE USER CREATE USER user IDENTIFIED BY PASSWORD 39 passwo
  • 用mysql触发器自动更新memcache

    mysql 5 1支持触发器以及自定义函数接口 UDF 的特性 xff0c 如果配合libmemcache以及Memcached Functions for MySQL xff0c 就能够实现 memcache的自动更新 简单记录一下安装测
  • 一个很爽的前端网站,有大量的资源

    http www gbin1 com technology css index html firstentry 61 0
  • Html5 Geolocation获取地理位置信息

    http www cnblogs com lwbqqyumidi archive 2012 11 10 2764352 html Html5中提供了地理位置信息的API xff0c 通过浏览器来获取用户当前位置 基于此特性可以开发基于位置的
  • openfire整合外部数据库的方法

    http www igniterealtime org builds openfire docs latest documentation db integration guide html 看了这篇教程 xff0c 发现了一个问题 xff
  • 金融机构如何应对核心系统分布式智能化升级大潮?

    过去40多年 xff0c 中国金融业实现了技术上的引进 借鉴 xff0c 并逐渐开始进行原创性创新 比如 xff0c 在 支付系统建设方面 xff0c 我国现在就走在了世界的前列 从二代大小额支付系统CNAPS到跨境人民币支付系统CIPS再
  • ajax请求中session无效的问题

    遇到一个问题 xff0c 发现网站中的所有ajax在某个服务器中的session总是无效 xff0c 后来同事查了资料 xff0c 原来php的配置文件中有个选项 xff1a Whether or not to add the httpOn
  • 解决seesion在二级域名下无效的问题

    开发中遇到了一个问题 xff0c 当用户在www aa com登陆了 xff0c 在二级域名下的登陆无效 例如 aa com 后来检查了很久 xff0c 终于知道了问题所在 xff0c 在www aa com下生成的cookie不适用于 a
  • 提供全球商家信息的网站

    做LBS的应用 xff0c 商家信息的获取和维护是个很重要的问题 xff0c 在中国的某些大型网站是雇佣了兼职人员去维护这些数据 xff0c 但对于小公司来说这种方法是不现实的 现在发现了一个网站 xff0c 提供了全球的商家信息 xff0
  • 使用web端连接xmpp

    在apache的配置文件中加入下面3句 xff1a ProxyRequests Off ProxyPass xmpp httpbind http 127 0 0 1 7070 http bind ProxyPassReverse xmpp
  • ubuntu apache开启重写模块

    http www iblue cc 2011 09 ubuntu apache E5 BC 80 E5 90 AF E9 87 8D E5 86 99 E6 A8 A1 E5 9D 97 Ubuntu下apache2的rewrite模块默认
  • openfire xmpp 如何判断用户是否在线

    http iammr 7 blog 163 com blog static 49102699201041961613109 想象中如此简单的功能 xff0c 想不到却这般大费周折 如要实现 xff0c 必须先确保 xff1a 1 openf