powered by Jive Software

Confused about Chat.addMessageListener

I created a chat and used chat.addMessageListener to add a PacketListener that I thought would receive a callback as each message came in. I was surprised to find out that the callback wasn’'t occuring. So I did some packet sniffing and sure enough, the packets were coming back but my callback was not being called. This led me to trying to place a PacketListener on the connection filtering for Message.class types. Sure enough, this worked.

Looking back at the original problem I started printing the thread id of the arriving messages and found out that it was null. This would explain why the chat.addMessageListener wasn’‘t working, as the filter it sets up uses the thread id to determine which messages qualify. null obviously didn’'t match the thread ID that my chat object was reporting.

So what needs to be done to get this to work by using chat.addMessageListener? Why don’'t arriving messages have a matching thread ID?

Hey dburger,

Use Chat#setFilteredOnThreadID(false) to disable the filtering on thread IDs.


– Gato

Yes, I got that to work, but I’‘m still confused as to why the thread ID is coming back as a null. Does that mean that the client that I am communicating with on the other end doesn’‘t correctly deal with thread id’'s?


The client that initiates the Chat should be including a thread element for tracking the conversation. If the thread element is not present then it’'s like sending isolated messages. I recall that there are some clients that do not include the thread element whilst others allow you to send isolated messages or start a conversation. Check if your client support both modes.


– Gato

Very helpful tip Gato! I was having the same problem, that is, not getting messages with a .messageListener() but getting them with a .packetListener().

For some reason though, I can''t seem to set the thread id and have it ''stick''. I''m currently using a GAIM client to talk my in-development SMACK client. I''m doing this all through a Jive IM Server setup on my machine.

Any ideas why the thread id doesnt seem to hold? I was wondering if it could be that GAIM doesnt support it?

Hey Kenneth,

I think that you should try opening the traffic window to confirm if Gaim is losing the threadID element. If that is the case you may want to post in the Gaim forums about this issue. Or let me know if you find that it’'s a Smack issue.


– Gato