Skip to main content

CLOSE Message

In case you want to "pause" current WebSocket wire you can send CLOSE message to server. This way the WebSocket connection will still stay alive even though no messages will be sent to the closed wire anymore. Following code example shows how you can send the wire CLOSE message to server.

let wire = 1; // Use same wire ID as was used in the related OPEN message for the targeted network

if (webSocket.readyState === webSocket.OPEN) {
const CLOSE = JSON.stringify({
"method": "close",
"wire": wire
});

webSocket.send(decodeURIComponent(escape(CLOSE)));
}

To re-open "paused" WebSocket connection you need to send the OPEN message again with same wire ID. For more information see OPEN message.