androidxmppsmackgoogle-talkasmack

Sending multiple chat messages using asmack to gtalk; Out of sequence


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 = "testing@gmail.com"  // 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


Solution

  • 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