WebSocket Protocol Architecture: Full-Duplex Framing & TCP Handshakes
The WebSocket protocol (standardized under IETF RFC 6455) provides persistent, full-duplex communication channels over a single TCP socket. Initiated via an HTTP Upgrade: websocket handshake, the connection transitions into lightweight binary/text framing with minimal per-message overhead.
1. Keep-Alive Heartbeats
Cloud load balancers (AWS ALB, Cloudflare, NGINX) terminate idle connections. Sending periodic lightweight ping/pong heartbeats maintains open state and verifies end-to-end network health.
Frequently Asked Questions (FAQ)
How does the WebSocket protocol differ from standard HTTP REST requests?
Unlike standard HTTP request-response cycles which open and close TCP connections per request, WebSocket (RFC 6455) maintains a persistent, full-duplex bidirectional TCP connection over a single socket, allowing server push with sub-millisecond overhead.
Why do WebSocket connections require heartbeat ping/pong frames?
Intermediate network proxies, load balancers, and NAT gateways automatically terminate idle TCP connections after 30 to 60 seconds. Periodic ping frames keep the connection alive.
Can this client connect to local development servers (localhost)?
Yes. You can connect directly to local development WebSocket servers running on localhost or 127.0.0.1 (e.g., ws://localhost:8080).