powered by Jive Software

Messaging with chat


The Smack 2.0.0 documentation suggests the following for 2-way chat:

GoogleTalkConnection connection = new GoogleTalkConnection();

connection.login(“user1”, “password”);

Chat newChat = connection.createChat(“user2”);

Message newMessage = newChat.createMessage();

newMessage.setBody(“Hi, I’'m an annoying parrot-bot! Type something back to me.”);

newChat.sendMessage(newMessage.getBody()); // note this line not in doc.

while (true)


System.out.println("in while(), newChat: " + newChat); // added

// Wait for the next message the user types to us.

Message message = newChat.nextMessage();

System.out.println(“after message”); // added

// Send back the same text the other user sent us.



When I run the above code, I get a valid connection and user2 receives the message sent by user1. However, I can’'t seem to receive chat back? Interestingly, the first println() is displayed but not the second. Thus, the program seems to be hanging at the call to Chat.nextMessage(). Does anyone know why?

Thanks for your help.