我在两台机器上有以下代码
var server = require('http').createServer(app);
io = require('socket.io')(server);
var redisAdapter = require('socket.io-redis');
io.adapter(redisAdaptebr({host: config.redis.host, port: config.redis.port}));
server.listen(config.port, function () {
我在中央数据库上存储连接到这两台机器的每个客户端的socket.id,正在保存套接字的ID并且在同一台服务器上发送的事件完美无缺,但是当我尝试将消息发送到其他服务器的套接字时不起作用..
subSocket = io.sockets.connected[userSocketID];
subSocket.emit('hello',{a:'b'})
答案 0 :(得分:1)
You can't. Socket.IO requires sticky sessions. The socket must communicate solely with the originating process.
You can have the socket.io servers communicate to each other to pass events around, but the client must continue talking to the process with which it originated.
答案 1 :(得分:0)
我遇到了类似的问题,但我可以回答你的第一个问题。 您可以在终端上使用该命令监视redis处理的所有命令:
redis-cli monitor
http://redis.io/commands/MONITOR
不幸的是,我无法帮助你,因为即使两个服务器都在向redis发送内容,我仍然遇到问题。