用这个来扯掉我的头发。。。有人能将Socket.IO扩展到Node.js 集群模块产生的多个“工作”进程吗?可以说我在四个工作进程(伪)上具有以下内容:// on the servervar express = require('express');var server = express();var socket = require('socket.io');var io = socket.listen(server);// socket.ioio.set('store', new socket.RedisStore);// set-up connections...io.sockets.on('connection', function(socket) { socket.on('join', function(rooms) { rooms.forEach(function(room) { socket.join(room); }); }); socket.on('leave', function(rooms) { rooms.forEach(function(room) { socket.leave(room); }); });});// Emit a message every secondfunction send() { io.sockets.in('room').emit('data', 'howdy');}setInterval(send, 1000);在浏览器上...// on the clientsocket = io.connect();socket.emit('join', ['room']);socket.on('data', function(data){ console.log(data);});问题:由于四个单独的工作进程发送消息,因此我每秒收到四条消息。如何确保消息仅发送一次?
添加回答
举报
0/150
提交
取消