简体   繁体   中英

Websokets(ws) , NodeJs Clusters,

I am building real time connection server. And want to scale it with Node Clusters

I went through many different websites trying to figure out how to implement Websokets(ws) and Node clustering. So the basic idea which i wanted to try is : I have and array of all users who are connected to the server , like : {key:ws, key:ws ,key:ws}

So what i want to do is to run Node js Clusters with Websockets , i will get some thing like that

Master : place to store all the connected ws in array : {key:ws, key:ws ,key:ws} Worker1 : Ws server to connect Worker2 : Ws server to connect

What i am wondering is for example user which is connected to the Worker2 wants to send message to user which is connected to the Worker2 and worker1.

So i will send message from Worker2 to the Master to get all the users , Master will send {key:ws(worker1), key:ws(worker2) ,key:ws} . And Worker2 will iterate over this array and send message to each user. Will that implementation work or message will not be send to the user which is connected to another Worker?

Thank you very much for the answer.

There is a package wse-cc that does fully-controlled user balancing between nodes, but the problem - it's not documented very well.

It uses different processes instead of clusters to make it able to work on multiple physical machines. I'm using it for browser MMO games. If you interested - I can make a quick doc on how to set up it. Not required any balancers on top, can work on a single machine or on multiple.

Or you can visit issues page - I'll help with any questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM