powered by Jive Software

Incoming chat not reaching listener

I downloaded 3.2.2 and made a couple of simple Google Talk clients using sample code I found out on the internet. I’m registering

a processMessage listener as follows;

public void processMessage(Chat chat, Message message) {

if (message.getType() == Message.Type.chat)

System.out.println(chat.getParticipant() + " says: "

  • message.getBody());

}

public void sendMessage(String message, String to) throws XMPPException {

Chat chat = connection.getChatManager().createChat(to, this);

chat.sendMessage(message);

}

I can send messages out and they reach the other party fine. But when the other party sends me a message it never reaches the listener. I can see the incoming packet in the Smack debug window and it looks fine. What am I missing?

Don’t create a new Chat for every message that you send. Since you don’t keep a reference to the Chat, each time a reply comes in it is creating a new Chat instance, which by default has no listener.

If you are expecting replies to an existing Chat, then maintain a reference to the Chat and replies will be directed to your listener. For new incoming chat messages (that aren’t replies) you will have to register a ChatManagerListener.

That did the trick, thanks. Seems like online examples should make in possible to do message traffic in both directions.