ionescu77 / my-channels-play-pub

MVP Django Channels 2 and WebSocket pure JS
0 stars 0 forks source link

Websocket closing a connection #1

Closed ionescu77 closed 4 years ago

ionescu77 commented 4 years ago
var textView = document.getElementById("text-view");
var buttonStop = document.getElementById("stop-button");

buttonStop.onclick = function() {
   // Close the connection, if open.
   if (socket.readyState === WebSocket.OPEN) {
      socket.close();
   }
}

https://www.tutorialspoint.com/websockets/websockets_closing_connection.htm

ionescu77 commented 4 years ago

It is also possible to pass the code and reason parameters we mentioned earlier as shown below.

socket.close(1000, "Deliberate disconnection");