socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

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.

Open WilliamGrant opened this issue 2 years ago • 2 comments

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? 20240108180558

Platform:

  • Device:i5 4590
  • OS: linux ubantu 20.9

WilliamGrant avatar Jan 08 '24 10:01 WilliamGrant

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?

darrachequesne avatar Jan 08 '24 16:01 darrachequesne

Yes! thank you for your reply. I will submit a feature request to netty-socket repository

WilliamGrant avatar Jan 09 '24 03:01 WilliamGrant

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

darrachequesne avatar Apr 08 '24 15:04 darrachequesne