var cluster = require('cluster');
var http = require('http');
var net = require('net');
var util = require('util');
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < 2; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
server = net.createServer(function(c) {
}).listen(8080);
server.on('error', function(e) {
console.log("local server connection error: %s", e);
})
server.on('listening', function() {
console.log("server listened on: " +
util.inspect(this.address()));
})
}
when first executed, outputs:
server listened on: { port: 8080, family: 2, address: '0.0.0.0' }
server listened on: { port: 8080, family: 2, address: '0.0.0.0' }
but in another terminals(another process, keep the first alive),
second executed, outputs:
server listened on: { port: 57093, family: 2, address: '0.0.0.0' }
server listened on: { port: 57093, family: 2, address: '0.0.0.0' }
57093 is a random port and change when restart process, and it's a
really work server on the port, is it expected?
I think the second process should get the EADDRINUSE error.
thanks!
On 2月7日, 下午10时49分, Shinuza <[email protected]> wrote:
> Not sure if I get this either.
>
> But from my understanding: if you run the Cluster
> example<http://nodejs.org/docs/latest/api/cluster.html#cluster>multiple times
> (i.e in two different terminals) the listening port will be
> shared across all of the workers.
> If you have 4 "cpus", using this example, you'd get 8 ( 2 x 4 ) workers and
> 2 masters. 10 processes. If I get it right, all of the workers will listen
> on the same port.
>
> If this is the excepted behavior then there is no reason to emit a
> EADDRINUSE.
>
> PS: @王 逍 when you said "master" did you mean the github repo?
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en