WebSocket
A protocol for real-time, two-way communication between a client and server.
WebSocket is different from HTTP. While HTTP is request-response based (half-duplex), WebSocket enables a persistent connection where data can flow in both directions simultaneously (full-duplex). This makes it ideal for applications requiring low latency and real-time updates, such as chat apps, live sports tickers, collaborative editing tools, and multiplayer online games. The handshake starts with an HTTP request that is 'upgraded' to a WebSocket connection.
graph LR
Center["WebSocket"]:::main
Rel_http["http"]:::related -.-> Center
click Rel_http "/terms/http"
Rel_tcp_ip["tcp-ip"]:::related -.-> Center
click Rel_tcp_ip "/terms/tcp-ip"
Rel_message_broker["message-broker"]:::related -.-> Center
click Rel_message_broker "/terms/message-broker"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧒 Explain Like I'm 5
Generated ELI5 content
🤓 Expert Deep Dive
Generated expert content
❓ Frequently Asked Questions
How is WebSocket different from HTTP?
WebSocket allows continuous, two-way communication, whereas HTTP is stateless and request-response based.
When should I use WebSockets?
Use them for real-time applications like chat, live notifications, or gaming.
Does WebSocket use TCP?
Yes, WebSocket runs over a single TCP connection.