August 2016
Intermediate to advanced
376 pages
6h 33m
English
Now is the time to create the socket.io event issues in our server. The socket.io allows you to send and receive events with any type of data:
Open app.js from the root folder and add the following lines of code at the end of the file:
// Starting with socket.io var io = require('socket.io').listen(server); // Create an Array to hold users var userList = []; // Create an Array to hold connections var connections = []; // Start connection listener io.sockets.on('connection', function (socket) { connections.push(socket); console.log("Connected:", connections.length ); // Setup Disconnect user socket.on('disconnect', function (data) { if (socket.username) { userList.splice(userList.indexOf(socket.username), 1); updateUsernames(); ...Read now
Unlock full access