Reputation: 699
I am creating a socket pass through inspector.
Basically, I start up a socket server (net.createServer
) and a socket client (net.connect
). For testing purposes, I do not have a endpoint socket waiting.
I want test whether the endpoint socket is available. If not, nodejs should wait until socket is 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);
});
});
Upvotes: 3
Views: 3426
Reputation: 310913
The best way to test whether any resource is available is to try to use it. Pre-testing is liable to a number of objections:
Upvotes: 1