Socket.IO
noun
say it: “SAH-kit EYE-oh” /ˈsɑkɪt ˌaɪˈoʊ/
A library for live two-way messages between browsers and a Node server, with rooms and reconnecting built in.
What is Socket.IO?
Socket.IO is a library built on top of WebSockets that adds rooms, named events and automatic reconnecting. The browser and the server must both use it, because it sends its own format over the connection.
import { Server } from "socket.io";
const io = new Server(3000);
io.on("connection", (socket) => {
socket.join("game-42");
io.to("game-42").emit("score", { home: 2, away: 1 });
});
In a sentence
- “A plain WebSocket client can't talk to a Socket.IO server, because Socket.IO adds its own format.”
- “The chat app switched to Socket.IO for its rooms and its automatic reconnects.”
Level: Journeyman · More Node.js terms at this level
Updated