Help with public chat in MUC Rooms:: NewB

Hello everybody,

I am trying to create a public room chatting application as a part of IM.

I am using Openfire 3.0.6a and smack.

I am able to create reserved room successfully, however the messages that i send to the room are not delivered in time, i mean if first message sent would be

“hi” form say “user1” + Enter, and

“how are you?” + Enter also bye “user1”,

everyone receives “hi” when i hit the enter key for the second time, and not at the first time as it is intended to work.

I am using sendMessage(Message m) for sending message.

Using addMessageListener(PacketListener p) for receiving the message, and code is nothing but extracting the body of the message and

displaying it, here is the code which i have implemented to receive messages to the room…

mc.addMessageListener(new PacketListener() {
public void processPacket(Packet packet)

{

 Collection<Message.Body> c =  mc.nextMessage(2).getBodies();

 for(Message.Body b :  c)
           System.out.println(b.getMessage())

}

}); //Closing the addMesageListener()

Cant figure out a way from this, would apprietiate if provided a working example of how to implement the, public chat using MUC class, or if any modification required…