How does WebSocket differ from HTTP?

Answer

HTTP is a request-response protocol: the client sends a request, the server responds, and the connection is closed (or kept alive briefly for reuse). The server can never push data to the client without the client first asking. WebSocket, by contrast, maintains a persistent connection after the initial HTTP handshake. Once established, both the client and server can send messages at any time — truly bidirectional. WebSocket also has significantly lower overhead per message: after the handshake, frames have only 2–14 bytes of overhead compared to HTTP headers that can be hundreds of bytes. HTTP is ideal for traditional request-response interactions; WebSocket is ideal for real-time, event-driven communication where the server needs to push updates unprompted.