WebSocket
WebSocket is a protocol that keeps a single connection open between a browser and a server so that both can send messages to each other at any time. With ordinary HTTP, the client must make a new request each time it wants data; with WebSocket, the server can push data the moment it is available.
The connection starts as an HTTP request that is "upgraded" to WebSocket, using ws:// or the encrypted wss:// URL scheme. It is used for chat applications, live notifications, multiplayer games, collaborative editing and live stock or sports scores.
const socket = new WebSocket("wss://example.com/chat");
socket.addEventListener("open", () => socket.send("Hello server"));
socket.addEventListener("message", (event) => {
console.log("Received:", event.data);
});