[英]Android socket io event and Channel
How to add event and channel?如何添加事件和频道?
private void initSocketConnection() {
try {
mSocket = IO.socket("URL");
connectSocket();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
private void connectSocket() {
try {
mSocket.connect();
mSocket.on(Socket.EVENT_CONNECT, onConnect);
mSocket.on(Socket.EVENT_CONNECT_ERROR, onError);
mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
} catch (Exception e) {
e.printStackTrace();
}
}
private Emitter.Listener onDisconnect = new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e("SOCKET_TEST", "DISCONNECTION SUCCESSFULL");
}
};
/**
* Receiver class for socket connected event
*/
private Emitter.Listener onConnect = new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e("SOCKET_TEST", "CONNECTION SUCCESSFULL");
}
};
/**
* Receiver for socket failed events
*/
private Emitter.Listener onError = new Emitter.Listener() {
@Override
public void call(Object... args) {
Log.e("SOCKET_TEST", "CONNECTION FAIL " + args.toString());
}
};
I send a request, returns 32:44/socket.io,"Invalid namespace"
need to send event and channel我发送请求,返回
32:44/socket.io,"Invalid namespace"
需要发送事件和通道
I use the library https://github.com/socketio/socket.io-client-java I do everything according to the documentation but nothing works.我使用库https://github.com/socketio/socket.io-client-java我根据文档做所有事情,但没有任何效果。
Instead of creating a socket with just:而不是仅使用以下内容创建套接字:
val socket = IO.socket("https://something.com/socket.io")
try the next code:尝试下一个代码:
val opts = IO.Options()
opts.path = "/socket.io"
val socket = IO.socket("https://something.com", opts)
I had the same issue getting 4/socket.io, "Invalid namespace"
trying to connect to the socket, and the code above fixed it.我在尝试连接到套接字时遇到了同样的问题,即
4/socket.io, "Invalid namespace"
,并且上面的代码修复了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.