我试图通过WebSocket库 socket.io 连接网址( wws://www.abc.com/ws?sid = sessionId0& mobile = 1 )在android中。我用android 5.1手机测试。我收到以下错误“io.socket.engineio.client.EngineIOException:xhr poll error”
注意:我研究过socket.io库不支持来自棒棒糖设备的 wws 安全连接。
String url = "wws://www.abc.com/ws?sid=sessionId0&mobile=1";
mSocket = IO.socket(url);
mSocket.on(Socket.EVENT_CONNECT, onConnect);
mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
mSocket.on(Socket.EVENT_CONNECT_ERROR, onConnectError);
mSocket.on(Socket.EVENT_CONNECT_TIMEOUT, onConnectError);
mSocket.connect();
private Emitter.Listener onConnect = new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e(TAG, "socket is connected");
if (!isConnected) {
if (null != mUsername)
mSocket.emit("add user", mUsername);
isConnected = true;
}
}
};
private Emitter.Listener onDisconnect = new Emitter.Listener() {
@Override
public void call(Object... args) {
isConnected = false;
Log.e(TAG, "SOCKET is disconnected");
}
};
private Emitter.Listener onConnectError = new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e(TAG, "error occurred while connecting to socket");
}
};
如何解决我的问题。建议将不胜感激。 在此先感谢:)
答案 0 :(得分:-1)
您需要添加互联网许可
<uses-permission android:name="android.permission.INTERNET" />