Skip to content

Instantly share code, notes, and snippets.

@wadey
Created January 3, 2011 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wadey/763992 to your computer and use it in GitHub Desktop.
Save wadey/763992 to your computer and use it in GitHub Desktop.
// This example attempts to time out before the connection is established
var net = require('net');
var start = Date.now();
var stream = net.createConnection(9999, 'google.com');
stream.setTimeout(1000);
stream.on('timeout', function() {
console.error('timeout:', Date.now() - start);
stream.end();
});
stream.on('connect', function() {
console.log('connect:', Date.now() - start);
stream.end();
});
// This example attempts to time out after the connection is established
var net = require('net');
var start = Date.now();
var stream = net.createConnection(80, 'google.com');
stream.on('timeout', function() {
console.error('timeout:', Date.now() - start);
stream.end();
});
stream.on('connect', function() {
console.log('connect:', Date.now() - start);
stream.setTimeout(1000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment