HTML and CSS Reference
In-Depth Information
Similarly to the previous example, we call the close() method when the user clicks
on the second button:
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();
}
}
It is also possible to pass the code and reason parameters we mentioned earlier:
socket.close(1000, "Deliberate disconnection");
Properties
The WebSocket objectexposessomepropertyvaluesthatletusunderstanditsspe-
cific characteristics. We have already met the readyState property. Following are
the rest:
Properties
Description
Returns the URL of the WebSocket
url
Returns the protocol used by the server
protocol
Search WWH ::




Custom Search