0

We have a problem in our project using the node ws websockets library. When the client looses network connection the only way to know that the client is disconnected is by sending a ws.ping() from the server. This is too resource consuming for us.

Does anybody know if there is a default way to get the ws server to use TCP level keepalives instead of using the ping/pong functionality?

larappa
  • 13
  • 1
  • 5
  • If you use socket.io on top of webSocket, the client will do a regular ping to the server. The client uses it to know when the connection died so it can do a reconnect. But, if the server knows that any "live" client will send a ping every X time interval, then the server can use the fact that it has not received such a ping in that X time interval to tear down a dead connection itself. Or, if you control the client, you can just configure your own ping interval even without socket.io. – jfriend00 Feb 05 '15 at 04:09
  • Thanks for the comment jfriend00. I have implemented a ping/pong functionality already but was looking for a solution for this that doesn't involve the application layer but rather just using the network layer. Found an answer here why TCP keep alives is not a good idea for websockets: http://stackoverflow.com/questions/23238319/websockets-ping-pong-why-not-tcp-keepalive The socket.io library is not usable for us since after v1.0 the lib doesn't seem to support the cluster module. That made me choose ws websockets. – larappa Feb 09 '15 at 17:57

1 Answers1

0

Solved this by letting the client send a response when a message is received.

larappa
  • 13
  • 1
  • 5