Skip to content

WebSocket

Medium — good to knowNetworking

ELI5 — The Vibe Check

WebSocket is like upgrading a walkie-talkie from push-to-talk to a full phone call. Normal HTTP is push-to-talk (you ask, server responds, connection closes). WebSocket keeps the line open so both sides can talk anytime. Perfect for chat apps, live dashboards, and games.

Real Talk

WebSocket is a full-duplex, bidirectional communication protocol over a single, persistent TCP connection. It starts with an HTTP handshake (upgrade request) then switches protocols. Unlike HTTP, either side can send data at any time without a new request.

Show Me The Code

// WebSocket client
const ws = new WebSocket('wss://example.com/socket');
ws.onopen = () => ws.send('Hello Server!');
ws.onmessage = (event) => console.log('Received:', event.data);

// WebSocket server (Node.js + ws library)
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });
wss.on('connection', (ws) => {
  ws.on('message', (msg) => ws.send(`Echo: ${msg}`));
});

When You'll Hear This

"Use WebSockets for real-time chat instead of polling." / "The live dashboard uses WebSocket to push updates without page refresh."

Made with passive-aggressive love by manoga.digital. Powered by Claude.