How WebSockets Work
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.
Legend — how to read this diagram
From HTTP to a live socket
- Upgrade request. The browser sends a normal HTTP request with an
Upgrade: websocketheader. - 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.
Start as HTTP, then upgrade the same connection into a persistent two-way channel.
The same clear explainers, delivered weekly. No spam, unsubscribe anytime.
Subscribe free →120+ page production guide: local LLMs, fine-tuning, RAG, and domain-specific AI.
Get the guide →AI implementation, fine-tuning and RAG done right. Free 30-minute strategy call.
Book a call →
No comments:
Post a Comment