Socket.IO is a mature and well-established library with excellent cross-browser support. It aims to quickly and reliably establish a bidirectional communication channel in a cross-browser compatible way. It provides a consistent abstraction, based on idiomatic JavaScript events, for real-time communication between the client and the server over this channel. If you have ever used SignalR in .NET, you can think of Socket.IO as the JavaScript equivalent.
Let's implement a chat lobby for users of our application to talk to one another. First, we need to install Socket.IO:
> npm install --save socket.io
The server-side implementation for this is very simple. We just need to tell Socket.IO that, whenever a user sends a chat message, we want to broadcast this to all connected users as given here src/realtime/chat.js
:
'use strict'; module.exports = io => { io.on('connection', (socket) => { socket.on('chatMessage', (message...