node.js - nodejs - How to test whether remote socket is open -
i creating socket pass through inspector.
basically, start socket server (net.createserver) , socket client (net.connect). testing purposes, not have endpoint socket waiting.
i want test whether endpoint socket available. if not, nodejs should wait until socket available.
var net = require('net'); var inbound = net.createserver(); var outbound = net.connect({ port: 8193 }); inbound.listen(8192, function () { //'listening' listener address = inbound.address(); console.log('server started on %j', address); }); inbound.on('connection', function (insock, outbound) { console.log('connected ' + insock.remoteaddress + ':' + insock.remoteport); insock.on('data', function (data, outbound) { outbound.write(data); console.log('data ' + data); }); });
the best way test whether resource available try use it. pre-testing liable number of objections:
- if tests different actual usage, may yield incorrect answer.
- if tests same things actual usage merely wastefully redundant.
- the situation may change between test , usage.
Comments
Post a Comment