Created
June 22, 2011 19:03
-
-
Save pgte/1040845 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 net = require('net'); | |
var connectTimes = []; | |
function connect() { | |
var socket = new net.Socket({type: 'tcp4'}); | |
var time = Date.now(); | |
socket.setTimeout(30000); | |
//socket.connect(5015, '66.228.62.138'); | |
socket.connect(5012, 'fragola.sfarm1.com'); | |
//socket.connect(5013, 'localhost'); | |
socket.on('connect', function() { | |
process.stdout.write('+'); | |
connectTimes.push(Date.now() - time); | |
socket.end('<policy-file-request />' + "\0"); | |
//socket.end('<auth tableid="144265" userid="121845" verify="cgnycuewiuajurbulpilxamvvrtzgdckcipsdqqiszuxrcdwxel" />' + "\0"); | |
}); | |
socket.on('data', function(data) { | |
process.stdout.write('reply'); | |
}); | |
socket.on('close', function(had_error) { | |
if (had_error) console.log('close. had error: ' + had_error); | |
}); | |
socket.on('error', function(err) { | |
console.log('error:' + err.inspect); | |
}); | |
socket.on('timeout', function() { | |
process.stdout.write('timeout'); | |
socket.end(); | |
}); | |
} | |
process.on('exit', function() { | |
console.log('exit'); | |
console.log('connections: ' + connectTimes.length); | |
var mean = 0; | |
connectTimes.forEach(function(ct) { mean += ct }); | |
if (connectTimes.length > 0) | |
mean = mean / connectTimes.length; | |
console.log('connection mean time' + mean); | |
}); | |
var count = 0; | |
;(function schedule() { | |
count ++; | |
connect(); | |
if (count < 1000) setTimeout(schedule, 100); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment