Last active
December 11, 2015 22:39
-
-
Save jrgm/4671535 to your computer and use it in GitHub Desktop.
Exercise the local ephemeral port range and see if it's exhausted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Exercise the local ephemeral port range and see if it's exhausted | |
// usage: `while [ 1 ]; do node ~/grab-a-socket.js; sleep 1; done` | |
var net = require('net'); | |
var options = { | |
port: 63300, | |
host: '127.0.0.1' | |
}; | |
var connectListener = function() { | |
var elapsed = Date.now() - startTime; | |
console.log(new Date().toISOString(), 'socket connected', | |
socket.address(), socket.remoteAddress, socket.remotePort, | |
elapsed + 'ms'); | |
socket.end(); | |
}; | |
var startTime = Date.now(); | |
var socket = net.connect(options, connectListener); | |
socket.on('data', function(data) { | |
var elapsed = Date.now() - startTime; | |
console.log(new Date().toISOString(), 'data', data.toString(), elapsed + 'ms'); | |
socket.end(); | |
}); | |
socket.on('error', function(error) { | |
var elapsed = Date.now() - startTime; | |
console.log(new Date().toISOString(), 'Error:', error.toString(), elapsed + 'ms'); | |
socket.end(); | |
}); | |
socket.on('end', function() { | |
var elapsed = Date.now() - startTime; | |
console.log(new Date().toISOString(), 'socket disconnected', elapsed + 'ms'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment