Created
December 29, 2014 07:25
-
-
Save hiroaki/7ee2e233959d6e8518dd to your computer and use it in GitHub Desktop.
Get empty port
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
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