Skip to content

WebSockets

SSE

According to the definition, it is a server push technology enabling a client to receive automatic updates from a server. Using SSE, the clients make a persistent long-term connection with the server. Then, the server uses this connection to send the data to the client.

Client can't send request twice

It is unidirectional, meaning once the client sends the request it can only receive the responses without the ability to send new requests over the same connection.

  1. The client makes a request to the server.
  2. The connection between client and server is established, and it remains open.
  3. The server sends responses or events to the client when new data is available.

WebSockets

WebSocket provides full-duplex communication channels over a single TCP connection. It is a persistent connection between a client and a server that both parties can use to start sending data at any time.

How this connection works?

The client establishes a WebSocket connection through a process known as the WebSocket handshake. If the process succeeds, then the server and client can exchange data in both directions at any time. The WebSocket protocol enables the communication between a client and a server with lower overheads, facilitating real-time data transfer from-and-to the server.

  1. The client initiates a WebSocket handshake process by sending a request.
  2. The request also contains an HTTP Upgrade header that allows the request to switch to the WebSocket protocol ws://
  3. The server sends a response to the client, acknowledging the WebSocket handshake request.
  4. A WebSocket connection will be opened once the client receives a successful handshake response.
  5. Now the client and server can start sending data in both directions allowing real-time communication.
  6. The connection is closed once the server or the client decides to close the connection.

Example

Step function example


Was this page helpful?
-->