Chapter 16: Example Real-time Multiplayer Quiz: WebSocket Code
Chapter 11 introduced WebSockets, which establish a two-way interactive communication channel between a client browser and server.
Our quiz application starts three WebSocket servers, and there’s no limit to the number of servers that could be started. However:
- A user will connect to a single server and remain connected to it throughout their session.
- Two users on the same game could be connected to different WebSocket servers.
Messages sent to and from the WebSocket server are typically simple strings, but we have the added challenge of coordinating messages across all servers!
Initiating a WebSocket Connection
The client-side JavaScript at web/static/js/main.js
initiates a connection ...
Get Node.js: Novice to Ninja 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.