当前位置:首页 > 开发 > 开源软件 > 正文

smack presence问题

发表于: 2009-07-22   作者:Blackbaby   来源:转载   浏览次数:
摘要: Roser#getPresence(String user) will return null if the contact has no presence information available. This could be because the contact is offline or you are not subscribed to their presence  

Roser#getPresence(String user) will return null if the contact has no presence information available. This could be because the contact is offline or you are not subscribed to their presence

 

If you are getting null when your contact is online then it will be (most likely) one of two things.

 

1: Either you are not subscribed to the other contacts Presence. In which case you will need to before you are allowed to track their Online/Offline status.

 

2: As AWenckus mentioned, it can sometimes take a moment for the information to be sent so if you are performing this operation as soon as you login the method may well return null.

 

Far better to add a RosterListener to your connection to listen out for Presence changes.

 

Presence presence = (Presence)packet;
Presence.Mode presenceMode = presence.getMode();

if(presenceMode == Presence.Mode.AVAILABLE) {
    // user is online and available
}

if(presenceMode == Presence.Mode.AWAY) {
    //user is away
}
take for example two users:User A,User B

User A wants to see when User B is online.

User A sends a SUBSCRIBE packet to User B

User B then decides whether or not to allow User A to see when they are online.

If they accept the subscription requests they send a SUBSCRIBED packet

If they reject the subscription request they send a UNSUBSCRIBED packet.

 

参考:http://www.igniterealtime.org/community/message/115077#115077

smack presence问题

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
OpenFire 是采用Java开发的基于XMPP(Jabber)协议,开源实时协作(RTC)服务器。 Smack 是用 Java
OpenFire 是采用Java开发的基于XMPP(Jabber)协议,开源实时协作(RTC)服务器。 Smack 是用 Java
OpenFire 是采用Java开发的基于XMPP(Jabber)协议,开源实时协作(RTC)服务器。 Smack 是用 Java
openfire的文件发送有两种: XMPP支持两种文件流传输协议,SOCKS5 Bytestreams和 In-Band Bytestrea
smack是什么?具体百度一下。我的理解也不深,我理解其实就是XMPP协议的实现。都是浮云,一切都是工
Openfire Server presence(在线状态)消息处理流程 2008-06-30 22:45 Presence处理是IM Server的核心
Openfire Server presence(在线状态)消息处理流程 Presence处理是IM Server的核心,也是一个IM Serv
Presence处理是IM Server的核心,也是一个IM Server最复杂的部分。一个用户的状态发生变化,需要通
Presence处理是IM Server的核心,也是一个IM Server最复杂的部分。一个用户的状态发生变化,需要通
XmpPullParser   鉴于xmpp协议都是以xml格式来传输,因此源码中解析协议都是用到XmpPullParser来
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号