Search code examples
javascriptwebsocketweb-applications

How do you keep a webSocket connection alive?


I need to design a web app that has a constant server connection, but the connection keeps failing.


Solution

  • You just have to use the following javaScript: webSocket.onclose=webSocket.open;. You can use webSocket.onclose=undefined; to force a connection to close.