你的位置:首页 > Java教程

[Java教程]6.nodejs权威指南


1. 进程

var net = require('net');

var cluster = require('cluster');

cluster.setupMaster({

      exec:'child.js'

});

var worker = cluster.fork();

var server = net.createServer();

server.on('connection',function(socket){

      worker.send('socket',socket);

});

server.listen(12345,'127.0.0.1');

worker.on('message',function(m,socket){

      console.log('子进程返回消息')

});

 

//child.js

process.on('message',function(m,socket){

      console.log(m);

});