Let's create a collaborative drawing application using socket.io and Node. We want to create a blank canvas that will simultaneously display all the pen work being done by connected clients:
From the server end, there is very little to do. When a client updates coordinates by moving their mouse, the server simply broadcasts this change to all connected clients:
io.sockets.on('connection', socket => { let id = socket.id; socket.on('mousemove', data => { data.id = id; socket.broadcast.emit('moving', data); }); socket.on('disconnect', () => { socket.broadcast.emit('clientdisconnect', id); });});
socket.io automatically ...