0

I am trying to send raw query in IQ in XMPP andriod, but it is not showing me any results. i am unable to receive any response, infact i do not know how to receive a response of Query.

here is the code of connection with server

public class NetworkOperation extends AsyncTask<String, Void, String> {

    public static XMPPClient xmppClient;
    public static XMPPConnection connection;
    public static ConnectionConfiguration connConfig;
    @Override
    protected String doInBackground(String... urls) {

        xmppClient = SettingsDialog.xmppClient;

        String host = "web.vlivetech.com"; //getText(R.id.host);
        String port = "5222";  //getText(R.id.port);
        String service = "web.vlivetech.com"; //getText(R.id.service);
        String username = "ssmack@web.vlivetech.com"; //getText(R.id.userid);
        String password = "123456"; //getText(R.id.password);

        // Create a connection
        connConfig = new ConnectionConfiguration(host, Integer.parseInt(port),service);
        connection = new XMPPConnection(connConfig);

        try {
            connection.connect();
            Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
        } catch (XMPPException ex) {
            Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost());
            xmppClient.setConnection(null);
        }
        try {
            connection.login(username, password);
            Log.i("XMPPClient", "Logged in as " + connection.getUser());

            // Set the status to available
            Presence presence = new Presence(Presence.Type.available);
            connection.sendPacket(presence);
            xmppClient.setConnection(connection);
        } catch (XMPPException ex) {
            Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
            xmppClient.setConnection(null);
        }

And here is the code of sending RAW QUERY through IQ packet which is right below connection

 PacketFilter filter = new IQTypeFilter(IQ.Type.GET); // or IQ.Type.GET etc. according to what you like to filter. 

        connection.addPacketListener(new PacketListener() { 
            public void processPacket(Packet packet) {
                // HERE YOU PUT YOUR CODE TO HANDLE THE IQ MESSAGE
                packet.toString();
            }
        }, filter);
        // IQ query code
       final IQ iq = new IQ() {
            public String getChildElementXML() { 
            return "<query xmlns='http://jabber.org/protocol/disco#info'/>"; // here is your query
            //this returns "<iq type='get' from='User@YourServer/Resource' id='info1'> <query xmlns='http://jabber.org/protocol/disco#info'/></iq>";
             }};
            // set the type
            iq.setType(IQ.Type.GET);
            // send the request
            connection.sendPacket(iq);

AM i missing something here?

Hassaan Rabbani
  • 2,469
  • 5
  • 30
  • 55
  • possible duplicate of [Sending and Receiving Custom IQ XMPP ANDROID ASMACK](http://stackoverflow.com/questions/22405405/sending-and-receiving-custom-iq-xmpp-android-asmack) – Flow Mar 14 '14 at 13:52

1 Answers1

0
PacketFilter filter = new IQTypeFilter(IQ.Type.GET);

Your filter is wrong. Responses to IQ of type 'get' are either of type 'result' or 'error'.

Flow
  • 23,572
  • 15
  • 99
  • 156
  • actually i do not know how can i get the response of my query am trying hard but unable to figure it out. in which variable will i get the response? right now i am unable to get any response with this code – Hassaan Rabbani Mar 11 '14 at 09:14
  • i am actually trying to get result of my query which is Disco#items. so why is it wrong? – Hassaan Rabbani Mar 11 '14 at 09:25