2

i have following code on two machines

 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 () {

and I store socket.id of every client connected to these two machines on central db, ID of sockets is being saved and event sending on same server works flawlessly, but when I try to send message to the socket of other server it doesn't work..

subSocket = io.sockets.connected[userSocketID];
   subSocket.emit('hello',{a:'b'})
  1. How can i know that redis is wokring good.
  2. How to send message to socket connected on another server.
Husnain Ashfaq
  • 142
  • 1
  • 7

2 Answers2

1

You can't. Socket.IO requires sticky sessions. The socket must communicate solely with the originating process.

docs

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.

tkone
  • 22,092
  • 5
  • 54
  • 78
0

I'm in a similar issue but I can answer your first question. you can monitor all the commands processed by redis using that command on the terminal:

redis-cli monitor

http://redis.io/commands/MONITOR

Unfortunately I cannot help you further as I am still having issues even though both server are sending something to redis.