Websockets and Server Sent Events
- 2022年8月30日
- 技術情報
Today, I would like to share about WebSockets and Server Sent Event (SSE). Both WebSockets and Server Sent Events are realtime push-based communication methods. Let’s explore at them.
WebSockets
WebSockets is a technology that enables bidirectional real-time interactive communication between a client and a server. WebSockets use the WebSocket protocol for communication.
Advantages
– WebSockets allow realtime bidirectional communication.
– WebSockets are supported in most of the latest browsers today.
– WebSockets don’t use XMLHttpRequest. So unnecessary data loads to the server are reduced.
– Binary data and UTF-8 text formats can be sent with WebSockets.
Disadvantages
WebSockets need TCP connection to work and don’t entirely need HTTP. They just need HTTP to initiate the connection for establishing standalone TCP connection that is used with WebSocket protocol. So some of HTTP functionality cannot be taken in WebSockets. The following are disadvantages of Websockets.
– No compression support
– Not support HTTP/2 mutiplexing
– WebSockets are not supported in old version browsers
– Setting up WebSockets is not simple and takes some time.
– May be issues for some firewalls with packet monitoring
Server Sent Events
SSE (Server-Sent Events) is a technology that allows a client browser to receive automatic updates from a server over a standard HTTP connection but not bidirectional. SSE use the JavaScript EventSource API.
Advantages
– Since SSE uses HTTP, it takes some advantages of HTTP functionality.
– SSE is easy to use and faster to setup.
– SSE will not cause problems with packet monitoring.
Disadvantages
– SSE does not allow bidirectional communication or data transmission.
– SSE can only send UTF-8 data and not binary data.
– SSE has restrictions about maximum number of open conenctions.
These are advantages and disadvantages of WebSockets and Server Sent Event. The case of choosing one of them depends on which solutions you want to solve and what your system needs.
This is all for now. Hope you enjoy that.
By Asahi
waithaw at 2022年08月30日 10:00:00