Need simplest example of sending/receiving message

Hello all.

I’'m looking for the simplest possible example of user1 sending a message to user2. Embarassing as this is I think it will be useful to a few non-technical people such as myself.

Here’'s the sending code:

XMPPConnection con = new XMPPConnection(“myserver.com”);

con.login(“user1”,“password”);

        Chat newChat = con.createChat("user2@myserver.com");

while (true) {

System.out.println(“SENDING TO USER2”);

newChat.sendMessage(“Howdy!”);

Thread.sleep(20000);

}

For user2 my misunderstanding has been along the lines of:

XMPPConnection con = new XMPPConnection(“myserver.com”);

con.login(“user2”,“password”);

        Chat newChat = con.createChat("user1@myserver.com");

while (true) {

System.out.println(“RECEIVING FROM USER1”);

Message message = newChat.nextMessage();

System.out.println(message.getBody());

Thread.sleep(20000);

}

Does users 2 need to initiate a chat with user1 just to receive messages from user1? Or does user2 need to implement:

MessageEventManager messageEventManager = new MessageEventManager(con);

with all of the code presented in the extensions section of your documentation?

It would be great to see an example of the simplest user2 chat message recipient code in your Messaging Basics section.

I do have user1 detecting the availability (presence) of user2 but no message transfer.

Thanks.

Tom

The problem was in using the createChat method which does not allow you to specify the thread ID.

My god, no one knew this?

Sometimes it’‘s easy to miss the obvious. You can set the thread ID once you’'ve created the chat object.

Regards,

Matt