NodeJS and socket.io messages dispatching best practices

时间:2016-02-12 19:41:06

标签: node.js sockets architecture server

We are in the process of writing a multiplayer game with NodeJS and websockets. When designing the architecture of the server we came up with the idea of objects handling most of their own communication.

First example on a connection we would then pass the socket to the client object who could then handle himself the communications. One of the advantage is not having to have a global handler that has to route the messages. This makes the responsibilities very well separated.

I can then also tell the client themselves to join a specific room with the socket.io functionality by sending them the room id.

The main disadvantage we can see is that there may be occurrence were we need to duplicate the sockets. ie: if a client disconnects from a room and wants to join another.

So the other option is going a more classical way and handling all the messages globally and then routing the with associated id's to the concerned objects.

Would you guys advise one solution over the other and why?

0 个答案:

没有答案