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:

  1. if tests different actual usage, may yield incorrect answer.
  2. if tests same things actual usage merely wastefully redundant.
  3. the situation may change between test , usage.

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -