node.js "Answering questions" : broadcast out to the rest of the connected clients

Problem

I'm trying to:

build a listening for the 'answer' event on the client, which will send us both the question and answer, which we want to broadcast out to the rest of the connected clients.

app.js =

var express = require('express');
var app = express.createServer();
var socket = require('socket.io');
var io = socket.listen(app);

io.sockets.on('connection', function(client) {
    console.log("Client connected...");

    // listen for answers here

   client.on('question', function(question) {
       client.get('question_asked', function(asked) {
           if(!asked) {
               client.set('question_asked', true);
               client.broadcast.emit('question', question);
           }
       });
   });
});
Problem courtesy of: Louis

Solution

You could use hook.io to talk to all the clients. This might be a good starting point.

Solution courtesy of: Erin

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.