Saturday, 10 June 2017

In socket i/o, how to send a message from an array of messages to respective room in an array of rooms without any loop?

socket i/o: I am using nodejs in my php application. I have an array of connected rooms say rooms={room1,room2,room3} and an array of respective message say messages={message1, message2, message3}.

Till now i am emitting my message as below:

io.sockets.in('room1').emit('message', 'message1');

This works fine but i am worried that once number of rooms will increase, looping over all will give performance hit as well as big delays.

Is there any way that i can directly send an array of message to an array of room like following?:

io.sockets.in(rooms).emit('message', messages);

which eventually should send message1 to room1... respectively.

thank you.!



via user3273860

No comments:

Post a Comment