HTML5 WebSocket and SSE – HTML API
Comparing WebSocket and SSE
WebSocket and SSE are both alternatives to the traditional request-response web architecture, but they are not exactly competing technologies. A WebSocket architecture consists of a socket that is opened between the client and the server for full-duplex (bidirectional) communication. Instead of sending a GET message and waiting for a server response, the client simply listens to the socket, receiving server updates and using the data to initiate or support various interactions. A client can also use the socket to communicate with the server, for instance by sending an ACK message when an update has been successfully received.
SSE is a simpler standard, developed as an extension of HTML5. While SSE enables asynchronous messages from the server to the client, the client cannot send messages to the server. SSE’s half-duplex communication model is best suited to applications where the client simply needs to receive streaming updates from the server. One advantage of SSE over WebSocket is that it works over HTTP, without requiring additional components.
For a multipurpose web application requiring extensive communication between client and server, WebSocket is the obvious choice. SSE is more suitable for applications that want to stream asynchronous data to the client from the server, but do not require a response back.