WebSocket
noun
say it: “WEB-sah-kit” /ˈwɛbˌsɑkɪt/
A lasting two-way connection between a browser and a server, so either side can send messages at any time.
What is a WebSocket?
A WebSocket is a connection between a page (or an app) and a server that stays open, so either side can send a message at any moment. Unlike plain HTTP, the server doesn't wait to be asked: it can push a new score the instant it happens.
const socket = new WebSocket("ws://localhost:8080");
socket.addEventListener("message", (event) => {
console.log(`New score: ${event.data}`);
});
In a sentence
- “The scoreboard opens one WebSocket and gets every goal the moment it's scored.”
- “A chat app uses a WebSocket so new messages appear without reloading.”
Level: Journeyman · More Web Development terms at this level
Updated