powered by Jive Software

Chat.nextMessage() blocks when receiving from Gaim/Psi clients

Hi there !

This is my first post on the forum so I’‘ll start with a few introducting words. I’'m a java beginner interested in developing a small application using the Jabber network.

The Smack library seems to be of great help, congratulations for the code clarity, and the richness of the doc

Now here’'s my question :

I’'ve tried to make the simple parrot-like app which is shown as an example in the doc but I ran into a few problems.

The most annoying one is that when receiving messages from the Gaim client, the Chat.nextMessage() simply blocks indefinitely. In fact, messages received from the Psi client does the same.

The app works just fine and as expected when receiving messages from the same account, this time using the ‘‘gnome-jabber’’ client.

I’‘ll continue investigating this (I haven’'t used the smack debugger yet, which might help in this case), maybe by trying to get messages at the Packet level.

In any case, if any of you has a clue on what might be happening… thanks in advance !

Best regards,

Nic

Message was edited by: nmaquet

I forgot to say that the app successfully sends any number of messages in all mentioned situations. It just doesn’'t receive any…

Right. Using the debugger (congrats, by the way, the tool’‘s brilliant !), I realized the messages really were coming in, no matter from which client. Here are the XML constructs I receive. The second one is well returned by Chat.nextMessage(), but the first one isn’'t :\

Doesn’'t work :

<message from=''sender.address@jabber.org/Gaim''
to=''receiver.address@jabber.org/Smack'' type=''chat''>
<x xmlns=''jabber:x:event''><composing/></x>
<body>The message as typed in the Chat window.</body>
<html xmlns=''http://jabber.org/protocol/xhtml-im''>
<body xmlns=''http://www.w3.org/1999/xhtml''>The message as typed in the Chat window.</body>
</html></message>

Works :

<message from=''sender.address@jabber.org/Home''
id=''102'' to=''receiver.address@jabber.org/Smack''
type=''chat''>
<body>The message as typed in the Chat Window.</body>
<thread>rbYTS0</thread>
<x mlns=''jabber:x:event''><offline/><delivered/><displayed/>
<composing/></x>
</message>

I’‘ll try to extract messages at the packet level from now on, instead of using .nextMessage() but I still don’‘t see why it isn’‘t working… Thanks anyway, Smack’'s great fun to tinker with

PS : “:x” should be “colon folowed by x”… It’'s strange that this forum displays smileys even when the text is under |code| |/code| (replace the pipes by you now what ) tags :S

Haven’‘t solved the problem, but here’‘s the workaround I found (wasn’‘t that bad, the Javadoc’'s a real gem !) :

// Add a Packet Listener (anonymous inner class)
con.addPacketListener(     new PacketListener() {        public void processPacket(Packet packet) {     
        Message msg = (Message)packet;
        if(msg.getBody() != null) {
            if(msg.getBody().equals("exit")) safeExit();
            try {
                chat.sendMessage(msg);
            }
            catch (Exception e) {debug("sendMessage() failed!");}
        }
    }
}, new PacketTypeFilter(Message.class));

My parrot-app’'s working with every client now

Nic,

If you take a look at both received messages you will see that the second one has a thread element. The Chat class will only return available messages if they belong to the chat. By default, Chat uses the thread element to recognize which message if part of the Chat. Since the first message doesn’'t include that element it is not being considered part of the chat.

If you want you can configure the Chat class to recognize a chat message based on the sender of the message instead of the thread element. Take a look at the static method #setFilteredOnThreadID(boolean).

Regards,

– Gato

Thanks so much !

Indeed, it works perfectly now… How strange though… when do you even need the thread id ? Does any jabber client support multiple chat windows while chatting with a single buddy ?

Doesn’'t matter much, it works

Btw, you might want to specify in the Javadoc that the call to #setFilteredOnThreadID(boolean) doesn’'t affect the behavior of the previously created instances of Chat objects (I checked :P), but only the new ones created after the call.

Thanks alot !

Don’‘t take me wrong, and please don’‘t take what follows as criticism. But as a Java beginner, I enjoy trying to understand the underlying design of what I use. So if you want to answer, great; and if not, that’'s fine, too !

Why is #setFilteredOnThreadID(boolean) a static method ?

At first, I thought it meant that all Chat objects should have the same behavior, one call affecting all previous _and _ future Chat instances. But it ain’'t so…

So, if you can have different instances of Chat objects with different filtering behavior, why not use a non-static method, instead ?

uh… “There are no dumb questions.”, right ?

thanx,u guy r so nice.