2
votes

How do I receive XMPP chat messages that are sent to a different resource?

E.g. my message listener receives messages fine, until that message gets replied to from another resource (like Gmail Google Talk). From that point on the messages are sent to that client resource and not my listener.

I'm using the Smack library for Java (well, actually asmack which is a port for Android)

After connecting to the service (Google Talk server), I add a listener like this:

    connection.addPacketListener(new PacketListener() {

        public void processPacket(Packet packet) {
            Log.i(TAG, "processPacket: chat");

            Message message = (Message) packet;

            Log.d(TAG, "Message: " + message.toXML());

            if (message.getBody() != null) {
                String fromName = StringUtils.parseBareAddress(message.getFrom());
                Log.i(TAG, "Got text [" +
                           message.getBody() +
                           "] from [" +
                           fromName +
                           "]");
            }
        }
    }, filter);

This works fine initially, I receive messages from Google Talk. These messages actually get sent to multiple clients, my desktop Google Talk, the Google Talk app an Android, and my implementation.

But when I reply to a message, say in the desktop application, all subsequent messages get sent to the desktop application resource, and I get nothing received in my implementation.

So I'm not sure how to also receive these messages. The Google Talk application seems to do this. It doesn't appear as a new message like it does initially (before it's replied to), but it does get updated in the Google Talk application thread.

Any help would be great!

2
Can you provide more information about your listener? Plattform, library?DrDol
Im using the smack library for java (well actually asmack which is a port for android), updated info in the question above.athor

2 Answers

3
votes

If I've understood you right, you are logged in with the same user on different applications (resources). You receive messages from contacts in your roster, but when you reply from one place, it creates a dialogue just between those two nodes?

This is implementation specific. Most clients follow the recommended behaviour in RFC 3921, which is to reply to a full JID (user@domain/resource) if the message received was from a full JID. You are free to reply using your from as your bare JID (user@domain), so that a future response in sequence will be sent to your bare JID, resulting in all your available resources (assuming priority is equal) receiving it.

From your example where you reply from your desktop application, it's likely that the application is setting its 'From' header to the full JID, and the other party whom receives the reply from your desktop application is then using that value as the 'To' header for its response. This of course means only that unique resource will get the messages.

So it's got nothing to do with your code. It's to do with the code in that desktop application, working in conjunction with the code at the other endpoint (the buddy you're talking to), that is cutting your implementation out of the loop.

0
votes

I think you should look up priority settings for that problem in xmpp. there is a priority settings that needs to be set so as to receive messages across different resources !

with multiple connection you need to control the message flow and so need to set priorities: Here are the basic rules for priorities: The resource with the highest priority at any given time will be the one which receives incoming messages. If two or more resources have the same priority, all resources with said priority will receive incoming messages. If all connected resources have a negative priority, incoming messages will be queued server-side until one of the resources resets priority to be positive.

source:http://blog.roobix.net/2010/02/jabber-xmpp-resources-and-priorities.html