O'Reilly logo

Learning Node.js for Mobile Application Development by Milorad Jevdjenic, Stefan Buttigieg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required