WebSockets and Server-Sent Events
WebSockets and Server-Sent Events keep a browser connected to a server so updates can arrive without repeated polling. WebSockets carry messages in both directions, while Server-Sent Events stream text events from server to browser over HTTP.
itWeb development | OpenSkills.info
Intro
WebSockets and Server-Sent Events
WebSockets and Server-Sent Events, or SSE, are browser technologies for receiving updates over a long-lived connection. A WebSocket becomes a two-way message channel. SSE keeps an HTTP response open so the server can stream text events to an EventSource client.
Both approaches reduce repeated polling when data changes independently of a page request. They solve different communication problems. WebSockets suit interactive traffic in both directions. SSE suits a server-to-browser feed when client commands can continue through ordinary HTTP requests.
Two connection shapes
A browser starts a WebSocket with an HTTP opening handshake. With HTTP/1.1, the client requests an upgrade and a successful server returns status 101. The connection then carries WebSocket frames rather than ordinary HTTP messages. Either endpoint can send a message at any time.
An SSE client makes an HTTP request whose response uses text/event-stream. The response remains open. The server writes UTF-8 fields such as event, data, id, and retry. A blank line ends one event block and lets the browser dispatch it. The browser does not send application messages back on that stream.
This directional difference is the central design choice:
Continue the course
This section is part of the paid course.
See pricing to subscribe, or log in if you already have access.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://www.rfc-editor.org/rfc/rfc6455
Supports
- WebSocket purpose, HTTP/1.1 opening handshake, status 101, and two-way message channel
- Text, binary, fragmented, close, ping, and pong frame behavior
- Client masking, server non-masking, Origin validation, subprotocols, and TLS guidance
- December 2011 publication milestone
- https://html.spec.whatwg.org/multipage/web-sockets.html
Supports
- Browser WebSocket constructor, events, ready states, send, close, and bufferedAmount
- https://html.spec.whatwg.org/multipage/server-sent-events.html
Supports
- EventSource interface, automatic reconnection, Last-Event-ID, and close behavior
- text/event-stream UTF-8 parsing, data, event, id, retry, comments, and blank-line dispatch
- SSE as a server-to-browser transport
- https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
Supports
- Practical browser API reference and absence of incoming backpressure in the classic WebSocket interface
- https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
Supports
- Browser and server implementation path for EventSource, named events, errors, and event streams
- https://www.rfc-editor.org/rfc/rfc7692
Supports
- WebSocket extension negotiation and permessage-deflate compression
- December 2015 publication milestone
- https://www.rfc-editor.org/rfc/rfc7936
Supports
- July 2016 clarification of the WebSocket subprotocol registry procedure
- https://www.rfc-editor.org/rfc/rfc8307
Supports
- January 2018 well-known URI suffix registration for ws and wss
- https://www.rfc-editor.org/rfc/rfc8441
Supports
- Extended CONNECT bootstrapping of WebSocket on an HTTP/2 stream
- September 2018 publication milestone
- https://www.rfc-editor.org/rfc/rfc9220
Supports
- WebSocket bootstrapping over an HTTP/3 stream
- June 2022 publication milestone
- https://www.w3.org/standards/history/websockets/
Supports
- WebSocket API Candidate Recommendation publication history
- https://www.w3.org/news/2011/w3c-invites-implementations-of-the-websocket-api-web-storage/
Supports
- December 8 2011 invitation for WebSocket API implementations
- https://www.w3.org/standards/history/eventsource/
Supports
- Server-Sent Events milestones from April 2009 Working Draft through December 2012 Candidate Recommendation and February 2015 Recommendation
- https://www.w3.org/wiki/Webapps/Interop/ServerSentEvents
Supports
- Implementation report for the December 2012 Server-Sent Events Candidate Recommendation
- https://www.w3.org/news/2015/server-sent-events-is-a-w3c-recommendation/
Supports
- February 2015 Server-Sent Events Recommendation and its scope
- https://github.com/sindresorhus/awesome
Supports
- Required starting catalog for awesome-list discovery
- https://github.com/facundofarias/awesome-websockets
Supports
- Discovery of Socket.IO, Centrifugo, SignalR, websocat, wscat, and libwebsockets as WebSocket ecosystem projects
- https://socket.io/docs/v4/
Supports
- Socket.IO transport fallback, reconnection, acknowledgments, rooms, and connection-state recovery
- Socket.IO placement in Awesome Links and Landscape
- https://centrifugal.dev/docs/getting-started/introduction
Supports
- Centrifugo channel fan-out, history, recovery, presence, WebSocket, HTTP streaming, and SSE transports
- Centrifugo placement in Awesome Links and Landscape
- https://learn.microsoft.com/en-us/aspnet/core/signalr/introduction
Supports
- SignalR hubs, message protocols, and fallback order across WebSockets, SSE, and long polling
- https://github.com/vi/websocat
Supports
- websocat command-line client, server, proxy, text, and binary capabilities
- https://github.com/websockets/wscat
Supports
- wscat interactive WebSocket client and server capabilities
- https://libwebsockets.org/
Supports
- libwebsockets role as a C client and server library for resource-conscious deployments
- https://ably.com/docs/protocols/sse
Supports
- Ably standards-based SSE adapter, subscribe-only behavior, and EventSource use
- Ably Pub/Sub placement in the managed realtime market
- https://pusher.com/docs/channels/
Supports
- Pusher publish-subscribe channels, WebSocket and HTTP transports, private channels, and presence
- https://www.pubnub.com/docs/general/channels/overview
Supports
- PubNub hosted channels and publish-subscribe messaging model
- https://learn.microsoft.com/en-us/azure/azure-web-pubsub/
Supports
- Azure-managed WebSocket connections, publish-subscribe hubs, groups, client protocols, and reliability guidance
- https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html
Supports
- API Gateway bidirectional WebSocket routes and integration with HTTP endpoints, Lambda, and AWS services
- https://developers.cloudflare.com/durable-objects/best-practices/websockets/
Supports
- Durable Objects as WebSocket servers, per-instance client coordination, and hibernation behavior
