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?