Judge a user's online or offline

If the Server want to get the presence status of a user, this is my method:

  1. createConnection: XMPPConnection cnn = XMPPConnection(“192.168.1.111:9090”); cnn.connecy();

  2. login: cnn.login(“aaa”, “bbb”);

  3. getRoster: Roster roster = cnn.getRoster();

  4. gePresnce; Presence ps = roster.getPresence(“jack”) the parameter “String user” is user’s JID or user’s nickname? please tell me

  5. judge Pesence; ps.getType == Presence.Type.onvailible

Is my method right? Please tell me, Thanks

lsc1202001 wrote:

If the Server want to get the presence status of a user, this is my method:

  1. createConnection: XMPPConnection cnn = XMPPConnection(“192.168.1.111:9090”); cnn.connecy();

First of all, 9090 is usually the port for the admin console, not for XMPP traffic. The default for XMPP clients is 5222 and 5223 (secure) respectively.

  1. login: cnn.login(“aaa”, “bbb”);
  1. getRoster: Roster roster = cnn.getRoster();
  1. gePresnce; Presence ps = roster.getPresence(“jack”) the parameter “String user” is user’s JID or user’s nickname? please tell me

The username, never the nickname, as it doesn’t need to be unique. I use

lRoster.getPresence(StringUtils.parseBareAddress(jid));
  1. judge Pesence; ps.getType == Presence.Type.onvailible

I use

// take care of users with multiple resources
        // presence value for the user with the highest priority and availability.
        String user = presence.getFrom();
        String userJID = StringUtils.parseBareAddress(user);
        Presence bestPresence =lRoster.getPresence(user);

Besides Presence.Type.available you can check Presence.Mode for availability.

Is my method right? Please tell me, Thanks

Please do have a look at the JavaDocs of smack.