First the code:
test.js:
var cluster = require("cluster");
if (cluster.isMaster) {
var app = cluster.fork();
app.on("message", function(code) {
console.log("Parent received: " + code);
app.send("this is from the test.js parent");
});
}
else {
process.send("");
process.on("message", function(code) {
console.log("Child received: " + code);
process.send("this is from the test.js child");
require("./testobj.js");
process.exit(0);
});
}
testobj.js:
process.send("this is from testobj.js");
process.on("message", function(code) {
console.log("testobj.js received: " + code);
});
process.send("this is the second message from testobj.js");
while (true) {}
The result when running node test.js
Parent received:
Child received: this is from the test.js parent
Parent received: this is from the test.js child
Parent received: this is from testobj.js
Parent received: this is the second message from testobj.js
Now that you see my work so far, the goal is to spawn sub processes independent of the parent but still retain two-way communications. The test code so far retains child to parent communication, but not parent to child. Does anyone have any suggestions on how to retain or re-establish parent to child communication?