I've been working with using socket.io with Android for a few days now. As of now, I am using AndroidAsync by Koush. When I try to connect to my local socket.io server (http://192.168.2.1:3000
) everything is okay, I can emit commands and receive event messages. But when I try to use it to a live server with query string parameters (http://api.mysite.com:8000/socket.io/1?v=1&name=xxx&password=xxx
) I cannot get to connect.
Is there a proper way of passing query strings 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) {
// TODO Auto-generated method stub
}
@Override
public void onConnect(AsyncHttpResponse response) {
// TODO Auto-generated method stub
super.onConnect(response);
Log.d("tag","onConnect!");
}
@Override
public void onProgress(AsyncHttpResponse response, int downloaded,
int total) {
// TODO Auto-generated method stub
super.onProgress(response, downloaded, total);
Log.d("tag","Progress!");
}
});
SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), myUrl, new ConnectCallback() {
@Override
public void onConnectCompleted(Exception arg0, SocketIOClient client) {
// TODO Auto-generated method stub
if (client.isConnected()) {
Log.d("tag","!");
} else {
Log.d("tag","?");
}
}
});