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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

So how can i send event from server, to another server's socket?
There are recommendations on how to do that at the bottom of the documentation to which I linked.
as mentioned above i tried the same doc, redis adapter. but no use :(
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.