const PORT=80;
const cluster=require('cluster');
var net =require('net');
var fs=require('fs');
if (cluster.isMaster) {
console.log('I am master');
cluster.fork();
var handle = function ( stream){
//console.log(cluster.workers[1].process.stdin);
stream.pipe(cluster.workers[1].process.stdin);
}
var server = net.createServer(handle).listen(80,'127.0.0.1');
} else if (cluster.isWorker) {
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
var chunk = process.stdin.read();
if (chunk !== null) {
process.stdout.write(`data: ${chunk}`);
}
});
process.stdin.on('end', () => {
process.stdout.write('end');
});
}
本来是想让主进程把请求转发给worker进程, 但是客户端一访问 http://localhost就报错
_stream_readable.js:501dest.on(‘unpipe’, onunpipe);