How do HTTP and WebSocket differ, and when should you use WebSocket?
Short answer
HTTP is ask and answer; the server can't send on its own. WebSocket upgrades from one HTTP request (101), and that connection becomes a long-lived two-way channel.
3 points to say:
- HTTP: the client always speaks first.
- WebSocket: two-way on the same TCP connection.
- Server-to-client only: use SSE.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.