TCP ping utility for node.js. You can test if chosen address accepts connections at desired port and find out your latency. Great for service availability testing.
ping
wrapper?ping
tool (as soon as connection gets accepted, it's dropped and a new measure is conducted immediately), so there's no unnecessary waiting between requests.npm install tcp-ping
options
is an object, which may contain several properties:
localhost
)80
)callback
should be a function with arguments in node convention - function(err, data)
.
Returned data is an object which looks like this:
{
address: '46.28.246.123',
port: 80,
attempts: 10,
avg: 19.7848844,
max: 35.306233,
min: 16.526067,
results:
[
{ seq: 0, time: 35.306233 },
{ seq: 1, time: 16.585919 },
...
{ seq: 9, time: 17.625968 }
]
}
callback
is a node style callback function(err, data)
, where data is true if the server is available and false otherwise.
var tcpp = require('tcp-ping');
tcpp.probe('46.28.246.123', 80, function(err, available) {
console.log(available);
});
tcpp.ping({ address: '46.28.246.123' }, function(err, data) {
console.log(data);
});