Receiving message doesn''t work

I’‘m trying to build a bot using smack, but it doesn’‘t work out… (It’'s the first time I try to receive a message.)

My code which comes from the example:

XMPPConnection.DEBUG_ENABLED = true;

XMPPConnection con;

try {

con = new SSLXMPPConnection(myserver);

con.login(mylogin,mypass);

Chat newChat = con.createChat(mycontact);

Message newMessage = newChat.createMessage();

newMessage.setBody(“Hi, I’'m an annoying parrot-bot! Type something back to me.”);

newChat.sendMessage(newMessage);

while (true) {

// Wait for the next message the user types to us.

Message message = newChat.pollMessage();

if (message == null){

}

else{

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

// Send back the same text the other user sent us.

newChat.sendMessage(message.getBody());

}

}

} catch (XMPPException e) {

e.printStackTrace();

}

This doesn’'t work at all, altough the debug tells me it has interpreted my response:

test

What do I do wrong?

Instead of doing the while loop, just add a packetlistener with message filter. It tends to be a little cleaner.

ex.

con.addPacketListener( this, new PacketTypeFilter( Message.class );

public void processPacket( Packet packet ) {

if( packet instanceof Message ) {

Message mes = (Message)packet;

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

newChat.createMessage().sendMessage( mes.getBody() );

}

That works but it’'s pretty strange to find an example straight from the docs not working…

Anyway, I am going to use a filter. It’'s much cleaner.

Thanks for your answer!

(And to the Jive people: thanks for your software, as a CS student finding good open source software is always usefull!)