WebSocket
Problem
HTTP naturally looks like: Client asks → Server responds
But imagine a chat application.
The server needs to send a message the moment another user writes, even when the browser hasn't just made a request.
Solution — WebSocket
Client and server establish a persistent bidirectional connection.
Secure WebSocket (wss://) typically starts with TCP → TLS → an HTTPS request to upgrade to WebSocket. The server replies “101 Switching Protocols”; WebSocket messages then flow over the same encrypted connection.
Client ↔ Server
Either side can send messages whenever needed.
Core idea: WebSocket provides persistent two-way communication.