我试着:
在客户端上为“answer”事件构建一个监听,它将向我们发送问题和答案,我们希望将其广播给其他连接的客户端。
应用程序.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);
}
});
});
});