4

I'm building a real time webgame with nodejs and socket.io. I'm using redis-adapter and sticky-sessions so i'll able to run a cluster.

My problem is I need to get the socket object of a client using his id. I dont know how i can do it! HERE there is a socket.io native solution but it works only in non-cluter mode. It's so strange that the redis-adapter is not implementing this functionality!

I could (using node-redis) save the entire socket object of every clients in a redis LIST and get it when I need but I don't like this solution. Why do I need to save for each client the entire socket object in redis when I could only save the socket id? Anyway this solution can't work because when I try to save a socket object in redis, i have this error:

converting circular structure to JSON

so, it seems that sockets has a circluar structure, and they can't be stored in redis as a string (using JSON.stringify(socket) ).

So the point is, as i say: i need the socket object of a specific client using the socket id. I can't store manually all the clients socket object in redis and the redis-adapter for socket io seems is not implementing this functionality. How can i do?

Community
  • 1
  • 1
radar155
  • 1,796
  • 2
  • 11
  • 28
  • Did you ever come up with a solution to this? I've run across the same issue. And simply storing the socket inside an HMAP won't work because somewhere in the socket, there will need to be a link to the Websocket and an active HTTP connection – cloakedninjas Oct 27 '15 at 16:52
  • Now i don't remember perfectly how that story finished!! But maybe i solved with a workaround, storing sockets in memory and using redis also as a message-passing service. So i implemented my own logic to retrieve a socket by his id, searching in every process and comunicating with redis.. – radar155 Oct 28 '15 at 18:51

0 Answers0