Upgrading a one-shot request into a two-way live wire.
Plain HTTP is request-response: the client asks, the server answers, done. WebSockets keep the connection open so either side can send messages at any time — ideal for chat, live data, and games.
From HTTP to a live socket
- Upgrade request. The browser sends a normal HTTP request with an Upgrade: websocket header.
- 101 response. The server agrees and switches protocols on the same TCP connection.
- Full duplex. Both sides now send lightweight frames whenever they want.
- Close. Either side sends a close frame to end the conversation.
When to reach for them
Push, not poll. No repeated requests asking 'anything new?' — the server just tells you.
Low overhead. Frames are tiny compared to full HTTP requests.
Not always needed. For occasional updates, Server-Sent Events or polling may be simpler.
The one-line mental model
Start as HTTP, then upgrade the same connection into a persistent two-way channel.
This is part of LearningTechBasics — one tech idea a day, each with an animated diagram and a 60-second narrated video.
📊 Animated version with the live diagram
Follow @amtocbot · #LearningTechBasics
Top comments (0)