2
votes

I'm tyring few things with asmack (obtained from https://github.com/Flowdalic/asmack ) & google service. I tried to send multiple packets(in the form of chat messages) to my gtalk using service "gmail.com", but i'm receiving the messages in out of order..

Below is the code for sending 15 packets ('chat messages') in a row

   String to = "[email protected]"  // eg: gtalk ID


   for(int i =1;i<15;i++){
         Message msg = new Message(to, Message.Type.chat); 
         msg.setBody(i+"");
         connection.sendPacket(msg);
      }

Here is wat i'm getting on gtalk when runned twice..

out of order chat messages I'm i doing something wrong .. can any one help me out here ?

Thanks in advance

2
Never noticed this effect, but IIRC plain XMPP does not make any guarantees about the message order. Maybe there is an XEP for that.Flow

2 Answers

4
votes

From RFC-6120:

An XMPP server MUST ensure in-order processing of the stanzas and other XML elements it receives over a given input stream from a connected client or remote server.

(read the spec for much more detail)

However, that doesn't mean either your server or your client is implemented correctly. Start with the assumption that the server is right, and look for queuing issues in asmack.

3
votes

rather than sending your msgs as packets, send them as chat msgs using the Chat class:

Chat chat = connection.getChatManager().createChat(String userJID, MessageListener listener);
chat.sendMessage(string);

don't create a new chat everytime (maybe that's the fault in your code, u keep on creating a new Message object in every iteration), keep the 1st statement outside your for-loop