Getting messages

i have the following method running on a thread that is called when the thread is started. my goal is to have a thread that waits for incoming messages.

public void process(){

while(true){

Message msg = chat.nextMessage();

String msgBody = msg.getBody();

System.out.println(msgBody);

}

}

problem is, no incoming messages ever received. am i doing it wrong?

I’‘d recommend turning on the debugging window so that you can see what traffic is coming to your client. Make sure the server and other client you’‘re talking to are preserving the thread ID since that’'s what Smack uses to track chat messages.

Regards,

Matt

i tried using a simple client (no thread) that waits for a reply after succesfully sending a message, still doesn’'t work.

i have a Chat instance chatSes. after sending the message i call

Message msg = chatSes.nextMessage();

my program seems to stop at that point.

and if i look at the debugger window, the reply message got received! but no return from the nextMessage() method…

a bit more information from the debugging window. when i replied, the server got my reply, but the client didn’'t.

hope somebody can help…

Can you paste in the relevant XML you’'re seeing from the debug window?

Regards,

Matt

from the client window:

a messagewcAhv0

from the server window:

<message type=’‘chat’’ to=’‘me@jabber.org/Smack’’ from=’‘me@yahoo.jabber.cz’’>a reply

from the interpreted package window:

a reply

so it looks like the reply has got to the server, yet when i call nextMessage() nothing happens…

yoga,

Notice how Smack sends a thread ID with the first message. However, the reply does not include that thread ID. Smack relies on that value for tracking which messages are part of a chat. So, to fix the problem, you’‘ll need to find out why the other chat client or server you’‘re using isn’'t using the thread ID.

-Matt

so where do the message id in the interpreted package come from? the Smack documentation says that “Interpreted Packets (green text) – shows XML packets from the server as parsed by Smack.”. doesn’'t that mean the my client do get the message ID?

or do the server need to send the ID too? how do i do this?

or is there any other way to get the incoming messages related to my chat session?

got the problem: replies from yahoo isn’'t being treated as part of a chat. i tried sending messages to and replying from Exodus, and it worked.

is there any way so that a reply from Yahoo/MSN/ICQ ca be recognized as part of the chat?

yonan,

I think this issue raises a really interesting question. Basically, is it better to:

  1. Only implement a really clean protocol and require that other clients always properly use a thread ID?

  2. Code in a work around for misbehaving clients?

If we decided on #1, you’'d need to modify the yahoo transport that your server uses so that it properly tracks thread ID. This should probably be a fairly simple change. If we decided on #2, anytime Smack got a message without a thread ID, it could loop through all active chats and deliver the message to the first chat with a matching JID. So, the #2 solution would work for this case, even though it might not be logically correct. Opinions?

Regards,

Matt

i’'m going to implement a packetlistener, and then filter out the messages coming from the desired userID (which is the recipient of my chat). what do you think of this?

oh, and my client currently only supports one connection, so it’‘d be much simpler, isn’'t it?

i’'m going to implement a packetlistener, and then

filter out the messages coming from the desired

userID (which is the recipient of my chat). what do

you think of this?

oh, and my client currently only supports one

connection, so it’‘d be much simpler, isn’'t it?

Yep, that should work with no problems. Just use something like:

PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class),         new FromContainsFilter("jdoe@jabber.org"));
// Create a packet listener or collector here

Regards,

Matt