I'll give a small premise of what I'm trying to do. I have a game concept in mind which requires multiple players sitting around a table somewhat like poker.
The normal interaction between different players is easy to handle via socket.io in conjunction with node js.
What I'm having a hard time figuring out is; I have a cron job which is running in another process which gets new information every minute which then needs to be sent to each of those players. Since this is a different process I'm not sure how I send certain clients this information.
socket.io does have information for this and I'm quoting it below:
In some cases, you might want to emit events to sockets in Socket.IO namespaces / rooms from outside the context of your Socket.IO processes. There’s several ways to tackle this problem, like implementing your own channel to send messages into the process. To facilitate this use case, we created two modules: socket.io-redis socket.io-emitter
From what I understand I need these two modules to do what I mentioned earlier. What I do not understand however is why is redis in the equation when I just need to send some messages.
Is it used to just store the messages temporarily?
Any help will be appreciated.
Well in the case of
socket.io
providing those, I read into that you actually need both. However this shouldn't necessarily be what you want. But yes,redis
is probably just used to store data temporarily, where it also does a really good job, by being close to what a message queue does.Your cron now wouldn't need a message queue or similar behaviour.
My suggestion though would be to run the cron with some node package from within your process as a
child_process
hook onto it's readable stream and then push directly to your sockets.