Answer the question
In order to leave comments, you need to log in
How to properly close a websocket?
Hello. For sockets I use the ws module. As soon as the user enters the site, I execute const ws = new WebSocket('ws://localhost:9000');
. This ws variable is then sent to the server and added to the array where all clients are stored. Accordingly, when the user left the site, I need to somehow remove one element from this array. How to implement it?
I tried to hang a handler on the client ws.onclose = function() {...}
, but it does not work when the user closes the tab
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question