-
Book Overview & Buying
-
Table Of Contents
Rust Web Programming - Third Edition
By :
A WebSocket is a TCP connection where multiple messages are sent back and forth between each other. This can reduce the overhead as we do not need to make new connections every time we need to exchange data. WebSockets are useful for push notifications, live updates, and data feeds, as we can continually push data from the server to the client, or vice versa. As the WebSocket is on top of a TCP connection, we can send any type of message we want. For instance, we can send binary messages or HTTP requests. The main feature of the WebSocket is that the TCP connection remains live, so multiple messages can be sent over that connection.
We can build a basic WebSocket with a simple TCP server and client setup. The overall mechanism is a TCP socket reader that runs in a loop to continuously listen to updates from the WebSocket, as seen in Figure 19.1:

Figure 19.1 – How to listen and process incoming messages over WebSocket
For our server workspace...