Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSockets with ws: Client closed or server closed?

Tags:

websocket

ws

In the ws Node.js WebSocket library, regarding the event socket.on('close', ...), is there any direct way (i. e. by inspecting the event) to determine if the client has closed the socket OR the server closed it for this client?

Even when the server explicitly sets a specific close code (4001), the handler on the server side for the close event gets a generic close code (1005).

So there is no way around but to remember it somewhere if the server closed the socket?

like image 402
Amaterasu Avatar asked Oct 15 '25 20:10

Amaterasu


1 Answers

If the client closed it, it knows it closed it. But if it doesn't then it must be server. The same thing can happen server-side

like image 89
Shiven Dhir Avatar answered Oct 19 '25 09:10

Shiven Dhir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!