Sending a socket to a child process

26 views
Skip to first unread message

Andrew Le Couteur Bisson

unread,
Oct 29, 2014, 8:01:51 AM10/29/14
to nod...@googlegroups.com
The following code works on Linux but not Windows:

server.js

var child = require('child_process').fork('child.js');


// Open up the server and send sockets to child
var server = require('net').createServer();


server
.on('connection', function (socket) {
    child
.send('socket', socket);
    server
.getConnections(function(err, count) {
        console
.log("Connections: " + count);
   
});
});
server
.listen(8081);

child.js

process.on('message', function(message, socket) {
        console
.log('Got socket');
        socket
.on('data', function(data) {
        console
.log(data.toString('utf8'));
   
});
});

Is this supposed to work on Windows 7?  The failure is that the data event is never fired.

Also, I have had no success in sending a partially read socket to the child on Windows or Linux.  What I am trying to do is to accept an http request in the server in the normal way and after reading the headers I want to sent the request socket to a child process to handle the body of the request.
Is it possible that the HTTP server has already read the request body from the socket by the time that the server callback is called?

Thanks,
Andy


Reply all
Reply to author
Forward
0 new messages