Загрузка…
Загрузка…
WebSocket — persistent full-duplex pipe после HTTP upgrade. Правильный tool для bidirectional real-time; reconnect, heartbeat, auth, scaling — на вас.
HTTP — half-duplex request/response: client asks, server answers, done. «Server tells me things» через poll — wasteful, laggy. WebSocket — long-lived pipe both ends write anytime.
HTTP polling WebSocket
──────────── ─────────
C → "anything new?" (req) C ══════════════ S ← one open pipe
S ← "no" (res) C → msg → ← either side
C → "anything new?" (req) C ← msg ← pushes freely,
S ← "no" (repeat forever) C → msg ← msg ← any timeWebSocket starts as HTTP. GET + Upgrade: websocket → 101 Switching Protocols → same TCP speaks WebSocket framing. Works on 80/443 through most proxies.
WebSocket = upgrade from HTTP to cheap duplex frames; ownership of reliability layer — yours.
