Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.