mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
636 B
26 lines
636 B
13 years ago
|
var net = require('net');
|
||
|
var received = 0;
|
||
|
var start = new Date();
|
||
|
var socket = net.connect(8000);
|
||
|
|
||
|
socket.on('data', function(d) {
|
||
|
received += d.length;
|
||
|
});
|
||
|
|
||
|
var interval = setInterval(function() {
|
||
|
// After 1 gigabyte shutdown.
|
||
|
if (received > 10 * 1024 * 1024 * 1024) {
|
||
|
socket.destroy();
|
||
|
clearInterval(interval);
|
||
|
process.exit(0);
|
||
|
} else {
|
||
|
// Otherwise print some stats.
|
||
|
var now = new Date();
|
||
|
var gigabytes = received / (1024 * 1024 * 1024);
|
||
|
var gigabits = gigabytes * 8.0;
|
||
|
var millisec = now - start;
|
||
|
var sec = millisec / 1000;
|
||
|
console.log((gigabits / sec) + " gbit/sec")
|
||
|
}
|
||
|
}, 1000);
|