powered by Jive Software

Why Roster.getPresence() always returns "unavailable"

Hi,

I have two questions:

Question 1) which is stated on subject.

I have successfully setup Openfire with a group and few users. One of the user is signin and Online. Then I tried simple code to query users presence status based on http://www.igniterealtime.org/builds/smack/docs/latest/documentation/roster.html

connection = new XMPPConnection(“localhost”);

connection.connect();

connection.login(“myuser”, “mypass”);

Roster roster = connection.getRoster();

Collection<RosterEntry> entries = roster.getEntries();

for (RosterEntry entry : entries) {

System.out.println(roster.getPresence(entry.getName()));

}

Above seems to return “unavailable” for all the users that found in a roster, but I know in fact one of the user is available. Is there setting am I missing?

Question 2) Is there way to query roster(list of user in a group) without performing a login? I simply want to display a custom Chat client where we retrict only group of user to chat with. The only solution I can see i I have to create a hidden user in that group in order to get the roster of all other member in the list. Is there a better way?

Thanks in advance for you help.

Hi,

For your question, you might want to put in a timer for waiting while the roster receives all of its presence events from Aim/Yahoo. Put a five second wait between loggin in and calling getPresence()

Hello Badiib,

I added 5 sec delay(I even tried 10), but still get “unavaliable” status What’s more strange is that I am able to see the connecting user: “myuser” shows up in my other loggined user group list as ONLINE(using Spark client), but just my code on other hand, can’t see anyone online.

If it helps, here are my system info: Smack3.0.4 with Openfire 3.4.2 on a MacOSX10.5 system.

Is there any more suggestion?

Ahh!!! I finally figured out to my own Question1!! Roster.getPresence(user) requires not only just the username, but the complete JID(with the ‘@domain’ part!). Ofcouse adding a delay as Badiib said also helps. This topic seems to come up a lot here, perhaps someone can update the doc on http://www.igniterealtime.org/builds/smack/docs/latest/documentation/roster.html???

Now, I am still waiting on my Question2 answer. Anyone has any suggestions for me please

Thanks.

thebugslayer wrote:

Question 2) Is there way to query roster(list of user in a group) without performing a login? I simply want to display a custom Chat client where we retrict only group of user to chat with. The only solution I can see i I have to create a hidden user in that group in order to get the roster of all other member in the list. Is there a better way?

Would you really want anyone to be able to read anyones roster? You have to identify yourself and be authenticated to be allowed access.

For your requirement, maybe a server-side plugin is more appropriate.

Hi

I am passing the complete JID to getPresence and also adding a delay between getting the roster and getting the presence of all contacts in the roster. But i still get presence as unavailable for all contacts. Any suggestions?!

Thanks!

Another thing to check: Make sure you have a subscription established between the current account and the user you are trying to get the presence for. You will not be able to get presence information until the subscriptions are approved by both accounts.

Chris

Hi Chris

Thank you for ur reply. The subscriptions are taken care of. I am facing this problem only when the clients are connected to a server on a remote PC. A server on the local machine returns all the presences without a problem. I am using the same clients in both the cases.

-Lata

for (RosterEntry entry: entries){

Presence presenceUser = roster.getPresence(entry.getUser());

}

You have to use getUser instead of getName!

Good luck!