Skip to content

Instantly share code, notes, and snippets.

@hiroaki
Created December 29, 2014 07: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 hiroaki/7ee2e233959d6e8518dd to your computer and use it in GitHub Desktop.
Save hiroaki/7ee2e233959d6e8518dd to your computer and use it in GitHub Desktop.
Get empty port
require 'socket'
class Util
def self.empty_port
s = TCPServer.open(0)
port = s.addr[1]
s.close
port
end
end
port = Util.empty_port
puts port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment