Defining the requirement
There are two techniques available for publishing real-time data on the web:
- Pull technique: This is where the client raises a request to get the latest version of data. HTTP polling and HTTP long polling are two examples of implementations of the pull technique.
- Push technique: This is where the server pushes updates to the client. WebSockets and Server Sent Events are two implementations of the push technique.
In general, push techniques have a lower latency compared to pull ones. We are not going to dive into these techniques in detail and compare them, as it is not the goal of this chapter. However, we will use the WebSocket technology for our requirement.
In short, the WebSocket protocol is a stateful communication protocol that establishes a low-latency bidirectional communication channel between a client and a server. This way, messages can be sent back and forth between the server and the client. The following diagram illustrates...