Question about receiving messages using SMACK with ejabberd


I have what seems to be a stupid question. I thave two users, usera and userb. Usera sends messages to userb but userb does not receive them (the processMessage method is not invoked).

After connecting both users create a chat and reference the other user and specify the MessageListener object.


// username = “usera”|“userb” + “

// port is the default 5222

String [] location = username.split("@");
ConnectionConfiguration config = new ConnectionConfiguration(hostname,
theConnection = new XMPPConnection(config);
theConnection.login(location[0], password);
theConnection.getChatManager().createChat(((location[0].equals(“usera”)) ? “userb” : “usera”)+ “@” +location[1],
new MessageListener() {

     public void processMessage (Chat chat, Message msg) {




It did not make sence so I enabled debugging. Once I did this I could see where userb was receiving messages but it did not appear to be invoking the method (nothing is printed to the terminal).

I am using the latest SMACK API (retrieved from svn 11/10/10). I cannot use the official 3.1.0 release because it will not connect to ejabberd (even with patch 264). If 264 is applied then the connect() will succeded but the login will fail (something about no response from the server).

Am I missing something when creating the Chat?



Message was edited by: Scott


Found the answer at: I must say that the answer is not obvious for someone new. It would be nice if there was an ‘addMessageListener(MessageListener)’ method in the XMPPConnection class. And of course add this to the examples in the documentation. It seems like receiving a message is completely skipped over.