powered by Jive Software

Smack chat to smack chat

I am trying, unsuccessfully, to have one smack code chat with another smack code. Seems straightforward. Code 2 logs in as user 2 and creates a chat with user 1. It then sets up a packet listener thread to process incoming chats. Meanwhile, code 1 logs in as user 1, creates a chat with user 2, and sends a message. If I leave code 2 out, an Exodus client logged in as user 2 receives the chat messages, but if I turn off Exodus and run code 2 to listen, I never receive anything.

I’‘m reasonably sure I have the packet listener stuff working correctly since I can successfully listen for MUC messages sent by Exodus or a smack code. It’‘s just smack to smack chat that I can’'t get working.

I must be doing something dumb. Can anyone tell me what? Better yet, how about a real working code example!


It would probably help to see the code.

It would probably help to see the code.

Okay, here are some code snippets. For simplicity, I’'ve replaced the packet listener code with the blocking ``


method in a loop.

The sender code looks like this:

 conn = new XMPPConnection (server);
 conn.login ("user1", "password1");
 Chat chat = conn.createChat ("user2@server");
 chat.sendMessage ("hello");

Then it sends more messages every 30 seconds in a loop.

The receiver code looks like this:

 conn = new XMPPConnection (server);
 conn.login ("user2", "password2");
 Chat chat = conn.createChat ("user1@server");
 while (true) {
 Message m = chat.nextMessage (10000);
 if (m == null) System.out.println ("no message...");
 else System.out.println (m.getBody ());

The receiver code never receives a message. However the Smack debugger window shows that messages are received, and the receiver code can successfully interact with an Exodus client.

Maybe it has something to do with the thread IDs. I’'m using a Smack 2.0.0 nightly build (either 14 Sep or 14 Nov) in which the thread ID handling has been changed and the ``


method has been removed.

Should I have both receiver and sender do a ``


to the other user? Maybe only one side should do the ``

. But how, then, would the other side get connected?


…and the isFilteredOnThreadID() method has been removed.

Oops. I meant the ``



Hmmm … seems my same problem … my client uses to do the same (when another user wants to chat with me, I open another Chat and listen to its events). This works fine when I chat with other clients (gaim, kopete, …) but fails when the other peer is my same client (of course, using another account ). I’'ve put some println() around and I see that the XPPConnection recevies the messages, while the Chat object does not

The code I use is pretty straightfoward:

Chat chat = connection.createChat( otherJid ); // Without the "/resource "

chat.addMessageListener( myListener );

MyListener.processPacket( Packet packet ) does never get anything so I suppose the Chat object does not get nothing, too.

But why? What else is needed to establish working Chat2Chat connection?


These are the kind of messages that i get logged:

My client

The id seems to cut off the the Chat from receiving the message … in 2.0.0 there was setFilteredOnThreadID() but it is no more here in 2.1.0 :S

Any suggestion will be helpful!

Ok, I looked at the doc and discovered that I can create a Chat specifying the threadId. So, when I receive a message for a chat that is not already open (I track the open chats in map), I just create a new chat object by specifying the threadId i get from the message itself.

Is this the expected way? Works for me, though.