ws: onclose not called if a client disconnects due to network failure
I am listening to the close event from a client on a node server using websocket.on('close', function close() { } );
However, the callback is not being fired if a client gets disconnected due to network failure.
Is there any way to detect dead connections on the server side ?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 10
- Comments: 15 (1 by maintainers)
I’ve got the same problem with detecting connections experiencing network errors. I’ve tried setting keepAlive, as pointed here, but
closeevent still fired only 10 s after network got down. Finally, I figured out how to use Websocket ping-pong mechanism:This is my implementation: https://github.com/urosjarc/websocketRest.js It’s used in production for 1 year +2000 mobile devices connected which are switching connections (wifi, 3G) all the time. We were having many problems with duplicats but now this lib is running 1 year without error. This is the company that use this lib: http://facilityforhotels.com/
A possible way to handle this issue is illustrated here: https://github.com/websockets/ws#how-to-detect-and-close-broken-connections. Closing, feel free to continue discussing on the closed thread.