find-free-port.rb
Path: util/find-free-port.rb
Modified: Fri Feb 21 01:16:25 MST 2003
Required files
socket   
Methods
find_free_port   
Public Instance methods
find_free_port(*args)

Find a free port to which to bind().

Optional arg host determines which interface to use. Default value is supplied by TCPServer.open(), and is, at the time of this writing, "localhost".

host
hostname for interface ["localhost"]
# File util/find-free-port.rb, line 49
def find_free_port(*args)
  args.push(0)
  gs = TCPServer.open(*args)
  port = gs.addr[1]
  gs.shutdown(2); gs.close
  return port
end