javascript websocket client timeout code example
Example: deal with Websocket timeout
let timerID = 0;
function keepAlive() {
let timeout = 15000;
if (webSocket.readyState == webSocket.OPEN) {
webSocket.send('');
}
timerId = setTimeout(keepAlive, timeout);
}
function cancelKeepAlive() {
if (timerId) {
cancelTimeout(timerId);
}
}