HTTP is a request-and-response protocol. The browser asks; the server answers; the connection closes. That shape works for fetching pages but falls over for any feature where the server has news to deliver and no idea when the browser will ask again. WebSocket is the answer to that mismatch: a single connection that stays open for as long as the page is alive, with either side free to send a message whenever it has one to send.
The handshake starts as an HTTP request that upgrades into the WebSocket protocol once the server agrees. After that the connection drops out of HTTP entirely and into a small binary framing format defined in RFC 6455. Both sides can send messages independently, with low overhead per message — usually a few bytes of framing on top of the payload.
Inside ShareCode the WebSocket layer is what carries Yjs document updates between connected clients in real time. Other patterns work for similar problems — server-sent events for one-way pushes, long polling for legacy environments — but for true bidirectional, low-latency communication in a browser, WebSocket is still the standard answer.