© Shing Lyu 2021
S. LyuPractical Rust Web Projectshttps://doi.org/10.1007/978-1-4842-6589-5_4

4. Chatting in Real-Time with WebSocket

Shing Lyu1  
(1)
Amsterdam, The Netherlands
 

So far, we’ve talked about how to send requests to an HTTP endpoint and get a response. However, under this architecture, only the client (i.e., the browser) can initiate communication. What if the server wants to notify the client about updates? What do the client and server need to be able to send messages to each other in real-time? In this chapter, we introduce another protocol called WebSocket, which provides full-duplex communication over TCP.

Introduction to WebSocket

In the traditional HTTP model, a client (e.g., a web browser) has to initiate a request, and the server ...

Get Practical Rust Web Projects: Building Cloud and Web-Based Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.