我尝试从Android应用/客户端连接到socket.io,但我一直收到以下错误
io.socket.engineio.client.EngineIOException:xhr民意调查错误
从服务器端(如后端人员所说),这是连接的代码
var socket = require('socket.io-client')('https://al3malh-geniusescode.c9users.io:8081', {
query: {
"session_key": '52c3cf92-34d8-4edd-8809-94679533a1c6'
}
});
socket.on('connection', function () {});
从android方面来看,(在持有代码的活动的onCreate方法中)代码是:
public Socket socket;
IO.Options options = new IO.Options();
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("session_key",readFromPreferences(MyApplication.getAppContext(), MyApplication.SESSION_KEY, ""));
} catch (JSONException e) {
e.printStackTrace();
}
options.query = jsonObject.toString();
{
try {
socket = IO.socket("https://al3malh-geniusescode.c9users.io:8081",options);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d("ActivityName: ", "CONNECTION");
}
});
socket.on(Socket.EVENT_CONNECTING, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d("ActivityName: ", "Trying To Connect");
}
});
socket.on(Socket.EVENT_CONNECTING, new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d("ActivityName: ", "Trying To Connect");
}
});
socket.on("on_error", new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d("ActivityName: ", "ERROR FROM SERVER"+args[0].toString());
}
});
socket.on(Socket.EVENT_CONNECT_ERROR,new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.d("ActivityName: ", args[0].toString());
}
});
socket.connect();
我正在使用的图书馆是
' io.socket:socket.io客户端:0.7.0'
并且清单中有权限(INTERNET)。
来自查询的问题是我在(Options.query)中作为字符串传递的吗?
任何帮助都将得到高度评价,在此先感谢