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.
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.
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?
I think this issue raises a really interesting question. Basically, is it better to:
Only implement a really clean protocol and require that other clients always properly use a thread ID?
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?
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