javascript - How to send data to some other client when one client connects in Socket.io , Node js? -


io.on('connection', function(socket) {     socket.on("event2", function(data) {         sendtoclient1(data, function(result){           io.to(socket.id).emit("emit_test" , json.stringify(data)); // works         });          sendtoclient2(data, function(result){           io.to(result).emit("emit_test" , json.stringify(data)); // not work         });      });      sendtoclient2:function(data, func){         red_client.get(data, function(err, reply){         console.log(reply);         func(reply);     }); }); 

here data username of second client socket id stored in redis server . not working in case . cannot receive emit data on second client ? doing wrong in here ?

you have not used socket.on catch emitted data client.


Comments