WebSocket vs Server-Sent Events
Both keep a line open so news arrives at once. A WebSocket lets both sides send. Server-sent events only flow from the server to the browser.
WebSocket
An open, two-way line between browser and server. Either side can send at any time.
A WebSocket is a link between a browser and a server that stays open. Both sides can send messages at any time. It starts as a normal web request, then upgrades to a two-way line. Messages arrive in milliseconds, with no new request for each one. Chat apps, live games and shared editors use it. Addresses start with ws:// or, when encrypted, wss://.
Server-Sent Events (SSE)
A server sends updates to the browser. They go one way, over plain HTTP.
Server-sent events let a server push updates to the browser. They flow over one web request that stays open. Unlike a WebSocket, messages go only one way, from server to browser. The browser listens with a built-in tool called EventSource, which reconnects on its own. Each message is plain text that starts with data:. It suits live scores, progress bars and AI answers that stream in.
In one line
- WebSocket
- An open, two-way line between browser and server. Either side can send at any time.
- Server-Sent Events (SSE)
- A server sends updates to the browser. They go one way, over plain HTTP.