gpt4 book ai didi

java - Android socket io事件和 channel

转载 作者:行者123 更新时间:2023-12-03 12:07:51 27 4
gpt4 key购买 nike

如何添加事件和 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());
}
};

我发送请求,返回 32:44/socket.io,"Invalid namespace"需要发送事件和 channel

我使用 https://github.com/socketio/socket.io-client-java库,我根据文档进行了所有操作,但没有任何效果。

最佳答案

而不是只创建一个套接字:

val socket = IO.socket("https://something.com/socket.io")
尝试下一个代码:
val opts = IO.Options()
opts.path = "/socket.io"

val socket = IO.socket("https://something.com", opts)
我在尝试尝试将 4/socket.io, "Invalid namespace"连接到套接字时遇到了同样的问题,上面的代码修复了它。

关于java - Android socket io事件和 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60869367/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com