node.js websocket crashes when client disconnect

前端 未结 3 1289
执念已碎
执念已碎 2021-02-10 16:11

I am very new to NodeJS and Websockets, but i am trying to play with it.

What i do is read incoming datas from Serial port, then send these dat

3条回答
  •  清酒与你
    2021-02-10 16:41

    Try this while sending data to client: - socket is my current web socket object.It overwrites the default >WebSocket.js class condition that throws "not-opened error".

    if (socket.readyState != socket.OPEN) {
        console.error('Client state is ' + socket.readyState);
        //or any message you want
    } else {
        socket.send(JSON.stringify(object)); //send data to client
    }
    

提交回复
热议问题