I have been working using socket.io with Android for several days. I'm currently using AndroidAsync from Koush. When I try to connect to the local socket.io ( http://192.168.2.1:3000) server , everything is fine, I can emit commands and receive event messages. But when I try to use it on a real server with query string ( http://api.mysite.com:8000/socket.io/1?v=1&name=xxx&password=xxx) parameters , I cannot connect. Is there a way to pass the query string parameter to AndroidAsync socket.io? Here is my code.
Uri.Builder b = Uri.parse("http://api.mysite.com:8000/socket.io/1").buildUpon();
b.appendQueryParameter("v", "1");
b.appendQueryParameter("name", "xxx");
b.appendQueryParameter("pass", "xxx");
myUrl = b.build().toString();
AsyncHttpClient.getDefaultInstance().getString(myUrl, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception arg0, AsyncHttpResponse arg1, String arg2) {
}
@Override
public void onConnect(AsyncHttpResponse response) {
super.onConnect(response);
Log.d("tag","onConnect!");
}
@Override
public void onProgress(AsyncHttpResponse response, int downloaded,
int total) {
super.onProgress(response, downloaded, total);
Log.d("tag","Progress!");
}
});
SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), myUrl, new ConnectCallback() {
@Override
public void onConnectCompleted(Exception arg0, SocketIOClient client) {
if (client.isConnected()) {
Log.d("tag","!");
} else {
Log.d("tag","?");
}
}
});
source
share