title: Send and Receive IQ XMPP ASMACK Android
body: <p><strong>Background:</strong></p>
  
  <p>I have been able to implement one to one chatting through <code>XMPP</code> in android using <code>asmack</code> library. I am able to send presence to the server as well. I am using <code>OpenFire</code> server for my Chat based application. </p>
  
  <p><strong>Problem:</strong>
  I am using <code>connection.addPacketListener(new PacketListener()</code>  to receive message and IQ packets, for message packets I have classified it like this</p>
  
  <pre><code>PacketFilter Chatfilter = new MessageTypeFilter(Message.Type.chat);
  connection.addPacketListener(new PacketListener() {
          public void processPacket(Packet packet) {
              Message message = (Message) packet;
              if (message.getBody() != null) {
                  String fromName = StringUtils.parseBareAddress(message.getFrom());
                  Log.i("XMPPClient", "Got text [" + message.getBody() + "] from [" + fromName + "]");
                  messages.add(fromName + ":");
                  m1=message.getBody();
                  messages.add(message.getBody());
                  // Add the incoming message to the list view
                  /* mHandler.post(new Runnable() {
                  public void run() {
                  setListAdapter();
                  recieve.setText(m1);
                  }
                  });*/
              }
          }
  }, Chatfilter);
  </code></pre>
  
  <p>And it is working all fine, but <strong>problem arises when</strong> I use something similar to receive IQ packets</p>
  
  <p>Here is the code which I am using to receive IQ PACKETS</p>
  
  <pre><code>PacketFilter Iqfilter = new IQTypeFilter(IQ.Type.RESULT);
  connection.addPacketListener(new PacketListener() {
      public void processPacket(Packet packet) {
          IQ iq = (IQ) packet;
          String fromName = StringUtils.parseBareAddress(iq.getFrom());
          Log.i("XMPPClient", "Got text [" + iq.toString() + "] from [" + fromName + "]");
          m1=iq.getFrom();
          mHandler.post(new Runnable() {
              public void run() {
                  setListAdapter();
                  recieve.setText(m1);
              }
          });
      }
  }, Iqfilter);
  </code></pre>
  
  <p>I am sending a simple <code>disco#items</code> query and it does not respond, even it does not enter into the function, I have tried to debug it as well, I have also tried to send simple <code>PING</code> command but it does not respond to it either. <strong>what am I missing here?</strong></p>
  
  <p>Secondly I am facing problems in sending IQ packets to the server as well or to some other client as well. I read somewhere that I should do it like this. but it does not work.</p>
  
  <pre><code>final IQ iq = new IQ() {
              public String getChildElementXML() { 
              return "&lt;query xmlns='http://jabber.org/protocol/disco#info'/&gt;"; // here is your query
              //this returns "&lt;iq type='get' from='User@YourServer/Resource' id='info1'&gt; &lt;query xmlns='http://jabber.org/protocol/disco#info'/&gt;&lt;/iq&gt;";
               }};
              // set the type
              iq.setType(IQ.Type.GET);
  
              // send the request
              connection.sendPacket(iq);
  </code></pre>
  
  <p>The confusing thing is when I read the documentation of XMPP and asmack for android it was written that to send an IQ you need to have receiver's address as well. but in this code we are not setting up any receiver.</p>
  
  <p>There is much less information available on internet for XMPP asmack and Android. </p>