Pavan K Pavan K - 1 month ago 25
Node.js Question

nodejs websocket detect disconnected socket

I have a nodejs websocket server and I have the following problem.

When my clients connect to the server and terminate gracefully the

onclose
method is called on those sockets and I perform clean up operations on the closed socket.

When the client disconnects due to network, the
onclose
method is not called. Is there any timeout to be set so
onclose
is called automatically after a timeout?

I am using ws package for the websocket server in nodejs

Answer

default ws implementation doesn't have a callback for network disconnects from client side

You can find a keepAlive implementation here

I am not sure why my post was downvoted. At least leave a comment what was wrong?