Hi,
I have written a code using smack API to login to my Openfire server and print all the contacts / buddy / Roster and also want to print the presence information of each user. I am able to login and print all the contacts and working OK.
But some times presence works and sometimes not. Also after successfull connection when i change the status of a perticular contact that “presence change” / “status change” doesn’t reflect in the Rosterlistener. (Changed to Busy From Available)
Is it possible to print the status messages from the contacts?
Can any body please rebview the code and confirm me that the code is correct?
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import javax.imageio.ImageIO;import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.smack.;public class IMClient {
// ++++++++++++++++++ RosterListener ++++++++++++++++++++++++++++ // public static void CreateRosterListener(Roster roster) { roster.addRosterListener(new RosterListener() { public void entriesAdded(Collection addresses) {} public void entriesDeleted(Collection addresses) {} public void entriesUpdated(Collection addresses) {} public void presenceChanged(Presence presence) { System.out.println("Presence changed: " + presence.getFrom() + " " + presence+ "\n"); } }); } // ++++++++++++++++++++ RetreiveRosters +++++++++++++++++++++++++++++++ // public static void RetreiveRosters(Roster roster,Collection entries) { Iterator it = entries.iterator(); while(it.hasNext()) { RosterEntry entry = (RosterEntry) it.next(); System.out.println(entry.getName() + " (" + entry.getUser() + ") ["+entry.getStatus()+ "] - [" + entry.getType() + "]"); } } public static void main(String args[]) { try { XMPPConnection connection = new XMPPConnection("Your Server IP"); connection.connect(); connection.login("UserName@domain", "Password"); Roster roster = connection.getRoster(); Collection entries = roster.getEntries(); CreateRosterListener(roster); RetreiveRosters(roster,entries); } catch(Exception e) { System.out.println(e); } }
}
Thanks In Advance
Soumyadipta De