Created
October 8, 2012 12:39
-
-
Save sorenso/3852305 to your computer and use it in GitHub Desktop.
logserver server.js.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require('cluster'); | |
var numCPUs = require('os').cpus().length; | |
if (cluster.isMaster) { | |
for (var i = 0; i < numCPUs; i++) { | |
cluster.fork(); | |
} | |
cluster.on('exit', function(worker, code, signal) { | |
console.log('worker ' + worker.process.pid + ' died'); | |
}); | |
console.log('This platform is ' + process.platform); | |
console.log('This processor architecture is ' + process.arch); | |
console.log('This process is pid ' + process.pid); | |
console.log(process.versions); | |
process.argv.forEach(function (val, index, array) { | |
console.log(index + ': ' + val); | |
}); | |
} else { | |
var dgram = require("dgram"); | |
var server = dgram.createSocket("udp4"); | |
server.on("message", function (msg, rinfo) { | |
var start = process.hrtime(); | |
var end = process.hrtime(start); | |
var total_time = end[0] + (end[1] / 1000000000); | |
console.log("server got: " + msg + ' from ' + rinfo.address + ', ' + rinfo.port + '. Time: ' + total_time + "\n"); | |
}); | |
server.on("listening", function () { | |
var address = server.address(); | |
console.log("server listening " + | |
address.address + ":" + address.port); | |
}); | |
server.bind(8080); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment