Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.io and cluster #1723

Closed
moshir opened this issue Aug 17, 2014 · 0 comments
Closed

socket.io and cluster #1723

moshir opened this issue Aug 17, 2014 · 0 comments

Comments

@moshir
Copy link

moshir commented Aug 17, 2014

Hi,

I've been using this step by step guide to enable cluster while using socket.io 1.0+.
Now, I can balance connections properly across workers, but I dont know how to pass events across workers.
My use case is simple
Client side, i have sockets connecting to namespaces (per object, e.g : let's assume a user sees a whiteboard).
When first user joins, one of the workers receives a http request and creates a room :

// creating and initializing a room
app.get("socketio").of(roomName).on("connection", function(socket){
    // implement the socket behaviour
    socket.on("join", ...) ;
})

With cluster enabled, new socket events might be redirected to different workers from the one the handlers where setup. Then, when testing if the room already exists (on any worker), we might miss the fact that the room was already created in another worker:

// testing if a room exists
 if (_.keys(app.get("socketio").nsps).indexOf(roomName) == -1) {
   // create the room :(
   app.get("socketio").of(roomName).on("connection", function(socket){
}

So my questions are :
1- Do you have any idea how we could adapt the code here so that we have a way to test room existence globally across workers ? I've done this by saving room names within a hash in redis, but wanted to know if it is supported by the adapter ?
2-How then to redirect events received from a worker to the actual worker where the handler was setup in? Is it supported also by redis adapter ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants