Skip to content

Instantly share code, notes, and snippets.

@robertklep
Created May 22, 2013 14:30
Show Gist options
  • Save robertklep/5627971 to your computer and use it in GitHub Desktop.
Save robertklep/5627971 to your computer and use it in GitHub Desktop.
var net = require('net');
var inbound = net.createServer();
var outbound = null;
setTimeout(function() {
console.log('starting to listen on :8192');
inbound.listen(8192, function () {
address = inbound.address();
console.log('Server started on %j', address);
});
inbound.on('connection', function(insock) {
console.log('inbound got a connection!');
});
}, 2000);
var interval = setInterval(function() {
console.log('lets check if port 8192 is open...');
outbound = net.connect({ port: 8192 });
outbound.on('error', function(err) {
console.log('...received an error', err.code);
});
outbound.on('connect', function() {
console.log('...outbound got a connection!');
clearInterval(interval);
});
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment