2010-10-15 19:05:22 +02:00
|
|
|
net = require('net');
|
|
|
|
|
|
|
|
var errors = 0, connections = 0;
|
|
|
|
|
2010-10-27 11:52:49 +02:00
|
|
|
var lastClose = 0;
|
|
|
|
|
2010-10-15 19:05:22 +02:00
|
|
|
function connect () {
|
|
|
|
process.nextTick(function () {
|
|
|
|
var s = net.Stream();
|
|
|
|
var gotConnected = false;
|
|
|
|
s.connect(9000);
|
2010-10-27 11:52:49 +02:00
|
|
|
|
2010-10-15 19:05:22 +02:00
|
|
|
s.on('connect', function () {
|
|
|
|
gotConnected = true;
|
|
|
|
connections++;
|
2010-10-27 21:08:47 +02:00
|
|
|
connect();
|
2010-10-15 19:05:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
s.on('close', function () {
|
|
|
|
if (gotConnected) connections--;
|
2010-10-27 11:52:49 +02:00
|
|
|
lastClose = new Date();
|
2010-10-15 19:05:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
s.on('error', function () {
|
|
|
|
errors++;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
connect();
|
|
|
|
|
|
|
|
|
|
|
|
var oldConnections, oldErrors;
|
|
|
|
|
2010-10-27 11:10:14 +02:00
|
|
|
// Try to start new connections every so often
|
|
|
|
setInterval(connect, 5000);
|
|
|
|
|
2010-10-15 19:05:22 +02:00
|
|
|
setInterval(function () {
|
|
|
|
if (oldConnections != connections) {
|
|
|
|
oldConnections = connections;
|
|
|
|
console.log("CLIENT %d connections: %d", process.pid, connections);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldErrors != errors) {
|
|
|
|
oldErrors = errors;
|
|
|
|
console.log("CLIENT %d errors: %d", process.pid, errors);
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
|