几天来,我一直在使用带有 Android 的 socket.io。截至目前,我正在使用 Koush 的 AndroidAsync。当我尝试连接到我的本地 socket.io 服务器 ( http://192.168.2.1:3000
) 时,一切正常,我可以发出命令并接收事件消息。但是当我尝试将它用于带有查询字符串参数(http://api.mysite.com:8000/socket.io/1?v=1&name=xxx&password=xxx
)的实时服务器时,我无法连接。是否有将查询字符串参数传递给 AndroidAsync socket.io 的正确方法?这是我的代码。
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","?");
}
}
});