Namespaces
Remember how we set up our original websocket
server? For that take a look at the following code:
// [snip] // Connect the websocket handler to our server var websocket = require('socket.io')(server); // Create a handler for incoming websocket connections websocket.on('UserConnectedEvent', function (socket) { console.log("New user connected"); // Tell others a new user connected socket.broadcast.emit('UserConnectedEvent', null); // Bind event handler for incoming messages socket.on('MessageSentEvent', function (chatData) { console.log('Received new chat message'); // By using the 'broadcast' connector, we will // send the message to everyone except the sender. socket.broadcast.emit('MessageReceivedEvent', chatData); }); });
Here, we simply ...
Get Learning Node.js for Mobile Application Development 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.