I have an http server and a forked child process. I want the parent to receive requests and go to the forked process using worker.send . and the worker should be able to process and send the response back to the requester using the same response object.
I tried to send the response object to the second parameter worker.send , but it gave the error This handle type can't be sent
var child_process = require('child_process'); var worker = child_process.fork(filename); http.createServer(function (req, res) { worker.send({ 'event': 'start' }, res);
I checked in the child_process.js file, and it says that if it does not belong to some types, it throws an error.
I want to know if there are other parameters by which I can send a response object to a forked child.
EDIT:
Ok, here is what I found, I just changed the following
// Instead of // worker.send({ 'event': 'start' }, res); worker.send({ 'event': 'start' }, res.socket);
And the forked process can invoke write on the receiver it receives.
Is it correct? Can I use it this way? or will there be any consequences in some conditions blah blah blah blah?
Salman
source share