Skip to content

Instantly share code, notes, and snippets.

@pgriess
Created June 9, 2010 18:21
Show Gist options
  • Save pgriess/431915 to your computer and use it in GitHub Desktop.
Save pgriess/431915 to your computer and use it in GitHub Desktop.
var net = require('net');
var s = new net.Stream(0, 'unix');
s.resume();
s.addListener('fd', function(fd) {
http.createServer(function (req, res) {
sys.debug("Got request at " + process.pid);
res.writeHead(200, {"Content-Type": "text/plain"});
res.end("Hello from " + proces.pid);
}).listenFD(fd, "tcp4");
});
var child_process = require('child_process');
var netBinding = process.binding('net');
for (var i = 0; i < 4; i++) {
var fds = netBinding.socketpair();
var cp = child_process.spawn(
'node',
['worker.js'],
undefined,
[fds[0], fds[1], -1]
);
child.stdin.write("http fd", "ascii", fd);
child.stderr.addListener('data', function (data) {
process.stdout.write(data);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment