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!
> 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