Socket.io by Guillermo Rauch is a revolutionary Node module that implements WebSockets in an intuitive JavaScript both on the Server and the client. The documentation is concise and clear.


To begin require socket.io and initialize on the server ...

var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(3000);

... and link to the library on the client:

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.2/socket.io.min.js"></script>

Then begin a connection on the server:

io.on('connection', function (socket) {
    // place socket code here.
});

and initialize the socket variable on the client:

var socket = io.connect('/');

Finally start passing messages around (making sure they share the same string identification).

On either the server or the client this code will send an object to all connected users:

socket.emit('some string', {toAll: 'is this fun or what?'});

And this will periodically receive emited information (placing it in either the client or the server)

socket.on('some string', function(data) {
  console.log(data);
});

From the server, you can send information to all users except the one who just sent it using:

socket.broadcast.emit('some string', {moreInfo: 'Oh yea'});

Homework

Create a Node server that receives information from each user and broadcasts that information to the other users.

Recommended

You might be inspired by James Surowiecki's talk on the Wisdom of Crowds.