Full-duplex realtime
- Client ↔ Server
- Both time communicate anytime
- One persistent connection
- Not request-response anymore
Normal HTTP
Browser Server
───── GET /products ──────>
<──── JSON response ───────
then connection done
Web Socket Workflow:
- HTTP handshake
- Upgrade to WebSocket
- Persistent connection
- Messages flow both ways
Browser Server
─────── CONNECT ──────────>
<────── CONNECTED ─────────
← connection stays open →
WebSocket Server
Connection 1
├── socket
├── user/client information
└── connection state
Connection 2
├── socket
├── user/client information
└── connection state
Connection 3
├── socket
├── user/client information
└── connection state
...
Connection 100
- Not mean the server is running a CPU loop for every user.
- “I have these sockets open. Wake me when something happens.”
- Use async/event-driven I/O, so one server process can manage many connections.