WebSocket: open event
WebSockets API
WebSockets API
The open event is fired when a connection with a WebSocket is opened.
Syntax
Use the event name in addEventListener():
addEventListener("open", (event) => { })
Alternatively, assign to the event handler property of the interface:
onopen = (event) => { }
Event type
A generic Event.
Examples
// Create WebSocket connection.
const socket = new WebSocket("ws://localhost:8080");
// Connection opened
socket.addEventListener("open", (event) => {
socket.send("Hello Server!");
});