I know it’s off-topic, but since the particle.io team has wide knowledge in node.js and the community seems to have it too, I have a question.
I am working on a server app using socket.io and node.js. I need to multiplex and route TCP messages and events in multiple levels. Kind of like an IP address, where the end point will always be a “cubicle” but will be arranged that a cubicle is contained in a building and a building is in a location. Any given location can have multiple buildings, and each buildings multiple cubicles :
So I envision an addressing system like:
So every time a new connection arrives to socket.io I am registering the socket in an array of clients or sockets.
So when I want to route a message or broadcasted from a cubicle to say every cubicle in a Building… I go and iterate the array and find all cubicles that are in a building.
My question is: will there be a performance gain by using multiple nested arrays where each array holds another level of the address. Say one array holds all the buildings, while each building holds all cubicles…
If I want to broadcast a message to all buildings in a location. All I do is fetch a location and then iterate thru all the buildings inside that location and then to all the cubicles inside the building and send the message to each socket or client.
Now I know I can use namespaces and rooms. But the problem is that I want to not be limited by two levels of multiplexing. So I rather roll out my own solution. I might consider the last level be a room. Say a building become a room of socket.io, so that I can simplify broadcasting to a building.
Any clues or if you can point me to the right place to ask, would be really appreciated I don’t want to code all the bolts in a bad path.
Thanks in advance!