Closed luoxiaofeng1029 closed 1 year ago
@mrniko
@mrniko Could you spare a few minutes to help me analyze this problem? It has been bothering me for a long time. Thank you very much.
@mrniko
V4 have some error 我修补它 https://github.com/lyjnew/netty-socketio-patch
V4 have some error 我修补它 https://github.com/lyjnew/netty-socketio-patch
我如何把官方的版本换成你的版本呢?
java8 https://github.com/lyjnew/netty-socketio-patch/files/11896219/netty-socketio-2.0.2-pach.jar.zip repalce netty-socketio-2.0.2.jar
java8 https://github.com/lyjnew/netty-socketio-patch/files/11896219/netty-socketio-2.0.2-pach.jar.zip repalce netty-socketio-2.0.2.jar
Thank you for your response. It is unfortunate that this author is no longer maintaining or addressing the issues we raised.
java8 https://github.com/lyjnew/netty-socketio-patch/files/11896219/netty-socketio-2.0.2-pach.jar.zip repalce netty-socketio-2.0.2.jar
I just replaced your patch, but I am still getting the error for my issue. I hope you can carefully review my description of the problem and the reference to another issue above. It seems like the current patch did not solve my problem.
@luoxiaofeng1029 give me you python-socketio connect code ,i test you code
@luoxiaofeng1029 给我你的python-socketio连接代码,我测试你的代码
`import requests import socketio import cv2 import base64 sio = socketio.Client(logger=True, engineio_logger=True)
@sio.event def connect(): print('connected to server')
@sio.event def disconnect(): print('disconnected from server')
if name == 'main': server_ip = '192.168.10.2' server_port = '8098' res = requests.post(f"http://{server_ip}:8088/benchLogin", json={"username": "admin","password": "123456"}).json() print(res) token = res['data']['token'] sio.connect(f"ws://{server_ip}:{server_port}?token={token}", transports=['websocket']) sio.wait() `
ok i find the error not the [netty-socketio] error the python-socketio client error ,i change client code ,all rgiht
error in python-socketio-main\src\socketio\client.py line 683 change this
if use public Python-socketio
i test use this code
sio.connect(f"ws://localhost:8080", transports=['websocket'])
client send nsp={} packet too
python-socketio-main\src\socketio\client.py 第 683 行中的错误更改此
After making the modifications as per your suggestion, the error is indeed resolved. However, is it really a mistake that the author of python-socketio added "or {}" at the end? I don't have extensive coding knowledge to understand the reason behind adding "or {}", so should I raise an issue to provide feedback to the developer? But I have previously approached this developer, and he mentioned that the server returned an incorrect message body.
ok i find the error not the [netty-socketio] error the python-socketio client error ,i change client code ,all rgiht
Additionally, I noticed that when python-socketio successfully connects, it triggers the "connect" event in netty-socketio twice.
` @PostConstruct public void start() {
// 为新命名空间添加事件监听器
server.addConnectListener(this::onConnect);
server.addDisconnectListener(this::onDisconnect);
server.addPongListener(this::onPong);
server.addPingListener(this::onPing);
server.addEventListener("message", String.class, this::onTextMessage);
server.addEventListener("videoStream", String.class, this::onVideoStreamReceived);
server.start();
}
private void onConnect(SocketIOClient client) {
LoginUser loginUser = JSONUtil.toBean(client.getHandshakeData().getHttpHeaders().get(LOGIN_USER_KEY), LoginUser.class);
client.set(LOGIN_USER_KEY, loginUser);
SocketIoClientHolder.addClient(loginUser.getUserId(), client);
log.info("[ws-connected] userId: {}", loginUser.getUserId());
SocketIOUtils.sendMessage(client, "from server: connect-success");
}`
@lyjnew
"This is also a standard. Returning this in JavaScript results in an empty set, which is normal if received by a Node service. Socket.io's Node version also follows this approach. However, Java may encounter issues with this. If you want to use this standard, modify the code at this location." netty-socketio\src\main\java\com\corundumstudio\socketio\protocol\Packet.java line 112 to this
“这也是一个标准。在 JavaScript 中返回这个会导致空值,如果由 Node 服务接收,这是正常的。Socket.io 的 Node 版本也遵循这种方法。但是,Java 可能会遇到问题。如果你想使用这个标准,修改这个位置的代码。” netty-socketio\src\main\java\com\corundumstudio\socketio\protocol\Packet.java 第 112 行 到此
我感觉还是按照你之前的方法,修改客户端的代码比较方便,哈哈,谢谢
nice
nice
are you chinese? You are truly very enthusiastic.
@luoxiaofeng1029
ok i find the error not the [netty-socketio] error the python-socketio client error ,i change client code ,all rgiht
Additionally, I noticed that when python-socketio successfully connects, it triggers the "connect" event in netty-socketio twice.
@lyjnew
======== **Socket.io protocol https://socket.io/docs/v4/socket-io-protocol/#connection-to-a-namespace
======================================================= i suggest not using the default namespace because V5 will change it https://github.com/socketio/socket.io-protocol#difference-between-v5-and-v4
@luoxiaofeng1029
好吧,我发现错误不是 [netty-socketio] 错误,而是 python-socketio 客户端错误,我更改了客户端代码,所有正确的代码
另外,我注意到当 python-socketio 成功连接时,它会触发 netty-socketio 中的“connect”事件两次。
@lyjnew
======== **Socket.io协议https://socket.io/docs/v4/socket-io-protocol/#connection-to-a-namespace
1. 客户端发送步骤1:连接打开发送0 --> 服务器返回:0{"sid":"a4b107b8-daad-4668-806a-3c60aa2ea060","upgrades":[],"pingInterval":25000," ping超时“:60000}
2.客户端发送第2步:connect open send 0+"namespace" --> 服务器返回:"namespace"+ {"sid":"f0aa3013-3475-468e-933f-6e4d07bfd7c3"}
您的命名空间设为空值,因此收到的连接请求。看起来像两次相同的连接,
3.如果有命名空间,那就不一样了。服务器还可以完全接收两个不同的连接请求,第一个是 nsp="",第二个是 nsp=chat
=================================================== = ===== 我建议不要使用默认命名空间,因为 V5 会更改它 https://github.com/socketio/socket.io-protocol#difference- Between-v5-and-v4
All of my questions have been resolved, thank you for patiently helping me clear all my confusions. I don't know how to express my gratitude.
fixed
issue details in python-socketio
The author of python-socketio told me that it is a server-side issue, but I can't seem to find the problem. Please help me by combining the link description above and the server-side code example below. Thank you.
`@Slf4j @Service public class SocketIOService {
}
@Slf4j @Configuration public class SocketIOConfig {
}
--- # socket.io socketIo: host: 192.168.10.2 port: 8098 bossCount: 1 workCount: 100 allowCustomRequests: true pingTimeout: 20000 pingInterval: 30000`