Nodejs cluster - socket.io-emitter send data to specific client

I am creating nodejs - socket.io application with nodejs node.

socket.io-Redis

var ioredis = require('socket.io-redis');
io.adapter(ioredis({ host: config.redisIp, port: config.redisPort }));

      

socket.io emitter

var io = require('socket.io-emitter')({ host: settings.redisIp, port: settings.redisPort });
io.emit('test', 'test'); 

      

works, but by sending to all connected sockets. How to select a specific client without using room types. eg,

io.to({_id: user._id}).emit('test', 'test'); //its not work. socket._id synchronized on connect event.

      

any idea for selecting a specific client in socket.io cluster application?

+3


source to share


1 answer


Try the following:



var io = require('socket.io-emitter')({ host: settings.redisIp, port: settings.redisPort });
io.to(socketId).emit('test', 'test');

      

0


source







All Articles