How to send a message to a buddy on the roster?

Hi,

I am confused … How would I send a message to a buddy on my roster.

When I send a message to “user@domain/Exodus” everything seems to work fine. Problem is that I don’'t know how to do aquire the fully qualified, i.e. with resource, jid. When adding a user to the roster with:

smackRoster.createEntry(“tu2@localhost/Exodus”, “Carmen”, new String[] {“A new group”});

Smack sends the following packets:

PacketListener WRITE: A New Group

PacketListener WRITE:

So far so good.

After that rosterModified() is called twice.

And I also get:

PacketListener READ: A New Group

PacketListener READ:

PacketListener READ: A New Group

In the latter entry there is just tu2@localhost and not tu2@localhost/Exodus. How should I send a message now? If I just send it to the short JID Exodus doesn’'t pick up the message. Only when I include the resource it picks up the message.

Am I missing the point? How can I talk to somebody on the roster when the roster omits the resource.

I first thought that I need to manage the resources when listening to the presenceChanged() calls, but they are also without the resource.

How do other people solve this?

Mariano

ps. I was talking about

String message = “xyz”;

String jid = “tu2@localhost”;

Message messagePacket= new Message(jid );

messagePacket.setBody(message);

connection.sendPacket(messagePacket);

When I specify the message type as chat, it works, but not for “normal” messages.

Message was edited by: mariano

Mariano,

In the latter entry there is just tu2@localhost and

nd not tu2@localhost/Exodus. How should I send a

message now? If I just send it to the short JID

Exodus doesn’'t pick up the message. Only when I

include the resource it picks up the message.

The entries that you are adding to your roster should be of the form user@domain. You should not try to add a <user@domain/resource> to the roster.

Am I missing the point? How can I talk to somebody

dy on the roster when the roster omits the resource.

Here is a copy&paste of the XMPP spec on “4.1 Specifying an Intended Recipient”:

“…If the message is being sent in reply to a message previously received from an address of the form <user@domain/resource> (e.g., within the context of a chat session), the value of the ‘‘to’’ address SHOULD be of the form <user@domain/resource> rather than of the form user@domain unless the sender has knowledge (via presence) that the intended recipient’'s resource is no longer available. If the message is being sent outside the context of any existing chat session or received message, the value of the ‘‘to’’ address SHOULD be of the form user@domain rather than of the form <user@domain/resource>…”

When you try to send a message to a user that is connected in more than one resource, if you don’'t specify the resource in the JID then the server will send the message to the resource with the highest priority.

When I specify the message type as chat, it works,

but not for “normal” messages.

That’'s strange. Which XMPP server are you using?

Regards,

– Gato

Hi Gaston,

thanks. Very interesting.

The entries that you are adding to your roster

should be of the form user@domain. You

should not try to add a <user@domain/resource> to the

roster.

Ok, I changed that.

When I specify the message type as chat, it works,

but not for “normal” messages.

That’'s strange. Which XMPP server are you using?

Jive Messenger. But anyway. It is now working both ways … No clue why. I tested it and I could repeat it with changing the messages to type chat or normal and it was working in the former and not working in the latter case. Probably an evironment problem?

Sorry for bothering you.

Cheers,

Mariano