XMPPConnection connection = new XMPPConnection("gmail.com");
try
{
// Connect
connection.connect();
// Login with appropriate credentials
connection.login("******@gmail.com", "*******");
ChatManager chatMgr = connection.getChatManager();
Chat chat = chatMgr.createChat("******@gmail.com", null);
chat.sendMessage("hello");
// Get the user's roster
Roster roster = connection.getRoster();
// Print the number of contacts
System.out.println("Number of contacts: " + roster.getEntryCount());
// Enumerate all contacts in the user's roster
for (RosterEntry entry : roster.getEntries())
{
System.out.println("User: " + entry.getUser());
}
}
catch (XMPPException e)
{
// Do something better than this!
e.printStackTrace();
}
finally
{
connection.disconnect();
}
try
{
// Connect
connection.connect();
// Login with appropriate credentials
connection.login("******@gmail.com", "*******");
ChatManager chatMgr = connection.getChatManager();
Chat chat = chatMgr.createChat("******@gmail.com", null);
chat.sendMessage("hello");
// Get the user's roster
Roster roster = connection.getRoster();
// Print the number of contacts
System.out.println("Number of contacts: " + roster.getEntryCount());
// Enumerate all contacts in the user's roster
for (RosterEntry entry : roster.getEntries())
{
System.out.println("User: " + entry.getUser());
}
}
catch (XMPPException e)
{
// Do something better than this!
e.printStackTrace();
}
finally
{
connection.disconnect();
}