Answer the question
In order to leave comments, you need to log in
How to pass data from one process to another process on nodejs?
Knowing the pid of the process launched using child_process.exec, is it possible to somehow transfer an object with data to this process at any time and vice versa?
I can’t use sockets, because I have to load the master process, and it needs to be protected from any influences as much as possible.
Answer the question
In order to leave comments, you need to log in
Just through sockets, you can transfer from one child process to another, but through child_process (and through cluster), i.e. through IPC (inter-process communication) everything will go only through the master process. Listen to UDP in each process, this is convenient if you need to send to everyone at once, and if only to a specific process, then when forking, give it a port number in the parameters and open a separate server TCP socket in each worker. The master process can send each worker a correspondence between ports and pid (if necessary), otherwise you can simply know that the ports go, for example, from 2000 to 2019 (that is, there are 20 of them open) and send to one of them.
https://ru.wikipedia.org/wiki/AMQP is not your option? With queues, sharding and other goodies and sparks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question