One of the ways a browser and a server exchange data.
The biggest difference from HTTP is that it is a persistent, bidirectional connection, so there is no reconnecting or resending of headers and other redundant overhead, and it responds more immediately.
WebSocket actually consists of two parts: a programming interface in the browser, and a transport protocol standard on the server side.
The formal IETF standard is RFC 6455.
You can choose the ws or wss protocol. ws is equivalent to plain http, and wss is equivalent to https, but the server must support it.
Because it is a persistent connection, the URI does not change during the connection, so you can only pick one URI at a time. To connect to a different URI, you have to open a new WebSocket connection.
Sending data is just a call to send(). To receive data, use the WebSocket onmessage event. Calling close() ends the connection.
On the server side, the first step is the handshake: an HTTP-compatible header that contains the WebSocket-defined header information. The server must process this information and return the processed result in its response headers. Once the browser has validated the headers the server returns, the two sides can establish the data link and exchange messages until close() is called.