Answers for "deal with Websocket timeout"

0

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);  
    }  
}
Posted by: Guest on November-20-2020

Browse Popular Code Answers by Language