HI, there is a problem about socket.io-client 4.7.0 and netty-socketio 2.0.6. The auth parameter causes the socket connection to fail and returns parse error.
Describe the bug I tried to use client(version 4.7.0) to connect to netty-socket(version 2.0.6). The client found that the disconnect event returned a parse error and requested a socket connection in a loop, resulting in a loop prompting disconnect parse error.When I remove the auth parameter, this problem does not occur.
To Reproduce
Please fill the following code example:
netty-socketio server version: 2.0.6
Server
package com.corundumstudio.socketio.demo;
import com.corundumstudio.socketio.*;
public class ServerConnectTest {
public static void main(String[] args) throws InterruptedException {
Configuration config = new Configuration();
config.setTransports(Transport.WEBSOCKET);
config.setHostname("192.168.0.24");
config.setPort(8096);
config.setNeedClientAuth(false);
config.setPingInterval(10);
config.setContext("/socket");
config.setAuthorizationListener(handshakeData -> {
System.out.println(handshakeData);
return AuthorizationResult.SUCCESSFUL_AUTHORIZATION;
});
SocketIOServer socketIOServer = new SocketIOServer(config);
socketIOServer.addConnectListener(client -> {
System.out.print("************ Client is connected ************");
client.sendEvent("connected", "You have successfully connected...");
});
socketIOServer.addDisconnectListener(client -> {
System.out.print("************ Client has disconnected ***************");
});
socketIOServer.addEventListener( "DATA",
Object.class,
(SocketIOClient client, Object data, AckRequest ackRequest) -> {
System.out.println(data);
});
socketIOServer.start();
System.out.println("Socket.IO server started");
Thread.sleep(Integer.MAX_VALUE);
socketIOServer.stop();
}
}
Socket.IO client version: 4.7.0
Client
import {EventEmitter} from 'events'
import {Socket as SIOSocket, connect as socketIOConnect} from 'socket.io-client'
import { WebSocket as WSSocket} from 'ws'
export class SocketTest extends EventEmitter {
protected readonly timestampParam?: string
protected client: SIOSocket | WSSocket
constructor() {
super()
}
public connect(url:string,path:string,port:number): void {
this.client = socketIOConnect(url, {
path: path,
forceNew: true,
autoConnect: false,
reconnection: false,
transports: ['websocket', 'polling'],
timeout: 20000,
timestampRequests: true,
timestampParam: this.timestampParam,
auth:{
configured: true,
id: 'ac111223-1b50-3cb8-a01f-df7948811b8d',
version:'1.0.1',
name: 'test_electron_device',
sn: '2cda9d57-4c9d-4488-8023-649adb56dbac',
key:'f485386a-4dd1-42b6-8c44-6d5d0c1ac7d8',
bc: 'MFEPMA_TP',
model:'Electric_DEVICE_001',
isPaused: false,
control: true,
automation: true
}
})
const sioClient: SIOSocket = this.client
sioClient
.on('connect_error', (connectError) => {
sioClient.sendBuffer = []
if (!this.destroyed) setTimeout(() => sioClient.connect(), 1000)
this.emit('connect_error', connectError)
})
.on('disconnect', (reason) => {
if (!this.destroyed) setTimeout(() => sioClient.connect(), 1000)
this.emit('disconnect', reason)
})
.on('connect', () => {
sioClient.sendBuffer = []
this.emit('connect')
})
.connect()
}
}
Expected behavior
The client found that the disconnect event returned a parse error and requested a socket connection in a loop, resulting in a loop prompting disconnect event(parse error). When I remove the auth parameter, this problem does not occur.I want to know whether it is because the socket server returned incorrect information, the socket client configuration is incorrect, or other problems. How to solve it?
Platform:
- Device:i5 4590
- OS: linux ubantu 20.9
Hi!
I dug a bit in the Java server source code, and it seems it does not currently support the auth option.
Reference: https://github.com/mrniko/netty-socketio/blob/master/src/main/java/com/corundumstudio/socketio/HandshakeData.java
Could you please open a feature request in the repository?
Yes! thank you for your reply. I will submit a feature request to netty-socket repository
This should be fixed now in version 2.0.7.
Related:
- https://github.com/mrniko/netty-socketio/pull/955
- https://github.com/mrniko/netty-socketio/issues/950