powered by Jive Software

Problems retrieving Presence information using the getPresence method

Hi folks, I’‘m new to these boards and new to Smack also! I am writing a limited chat client that uses a Jive Messenger server. I’'m having a problem with the getPresence method from the Roster class. I have the following bit of code in my connection method;

try {

this.connection = new XMPPConnection(localhost, 5222);

this.connection.login(“aoraki”, “aoraki”);

} catch (XMPPException e) {

}

Roster roster = connection.getRoster();

if (roster.getEntryCount() > 0){

for (Iterator i=roster.getEntries(); i.hasNext(); ) {

RosterEntry rosterEntry = (RosterEntry)i.next();

Presence presence = roster.getPresence(rosterEntry.getUser());

if(presence != null)

System.out.println("The value of presence.toString() is " + presence);

}

}

The connection with the server is being made correctly, and I’‘m getting the correct roster that is associated with the user that I’‘m using to log in. But the presence info is being returned as null, even though some of the roster entries are currently logged in and are online (verified through the Jive admin console). I can get presence packets no problem when a change occurs with a roster entry’‘s presence. But for some reason I can’'t get the presence when I make the initial connection and use the .getPresence method. Am I missing something here? Is there a solution / workaround to this or is this a known problem? If anybody has any ideas I would appreciate their input. Many thanks folks!

aoraki

Can you see in the debugger console if you are recieving initial presence from the users in question? I have two thoughts, one that you might be experiencing a race condition and two that you may not be properly subscribed to the user’'s presence.

Hope that helps,

Alex

Most likely the server has not yet sent you the presence information. It takes a bit for this to happen.

Hi AWenckus, thanks for the response. I’‘m not sure what you mean by “race condition”, can you clarify that please? As to your second point, I was thinking the same thing myself. But surely if my test user was not properly subscribed to other users presence, then I wouldn’‘t be able to receive presence updates from them. I can receive presence updates from users in my roster without any problems. After I’'ve done the initial login, (and failed to get the presence using the getPresence function), if one of the users on my roster changes his presence status, I am receiving that information with no problems.

Another puzzling thing is, every now and again is does actually work. But it doesn’‘t happen that ofter and it’‘s very inconsistent. It could just be my server dragging it’'s ass reponding to presence requests. Tis puzzling so it is!

Anyway, thanks for taking the time to respond - appreciate it.

Aoraki,

One thing to keep in mind…

If you have added users to your roster, and they have not authorized your subscription to their presence, their presence will appear null to you.

Try setting up your accounts with GAIM, then log in through your client and view your roster again.

-Ken

Hi Synic, thanks for that. As I said to AW, the getPresence method does sometimes work, but it doesn’‘t happen that often and it’‘s very inconsistent. However, if there is a delay, it’‘s taking a long time for the presence info to come back, because I’‘ve had the chat client open for 10 mins at a time, and the presence info still hasn’‘t come back by the time I’'ve closed the client. Ho hum! Anyway, thanks for your response.

If they are not in your roster then you are not subscribed to them. What i meant by race condition was exactly what synic said, he just explained it better

Kenneth, I’'ve set up all my accounts and user groups through the admin console that comes with Jive Messenger. The roster of users for my test user is coming back with no problems. What is GAIM exactly?

Sorry…I should have spelled that out! GAIM is an open source instant messenger. I use it to test my own Smack client. Its invaluable when trying to debug my own code.

I’‘d be curiouse to see how many entries there are in your Roster. Based on what you’‘ve said here (configured accounts only through the Jive Server) I’‘m surprised you ever see anything in it. Theres no way (that I’'ve found) to add roster entries through the server console.

Two questions:

  1. What does yourRoster.getEntryCount() yield?

  2. What does yourRoster.getSubscriptionMode() yeild?

-Ken

-Ken

For the user, don’'t you need to specify a domain? user@domain?

Noah

Hi Kenneth,

you can create users through the Jive admin console, in the Users/Groups link. The way I set up all my users is that I created a number of different users and user groups and grouped my users as per business rules. When I log in using a member of a particular group, I can see all the other members of that group in my roster, which is the functionality I’'m looking for.

The result of roster.getEntryCount() is 4 (which is correct)

The result of roster.getSubscriptionMode() is 0 (not sure if this is correct or not)

By the way, I’‘m using an Exodus client when I’‘m testing my chat functionality. I’‘m developing my chat client which sits in a bigger application and to test conversations, I’'m chatting to another user (which is me!) and the other user is using an Exodus chat client.