From: GOTOU Yuuzou Date: 2005-03-21T04:46:10+09:00 Subject: Re: can WEBrick bind to port 0, and then tell me what port was allocated? Hi, In message <20050320193414.GD911@ensemble.local>, `Sam Roberts ' wrote: > I don't create the socket, WEBrick does. I can't find a WEBrick API that > gives me back the socket, so I don't have a way to call > #getsockname on it to find the port. > I also can't find a WEBrick API where I create the TCPSocket and pass it > in, that would work for me, too. WEBrick::GenericServer#listen and #listeners may be useful. % ruby -r webrick -e ' s=WEBrick::HTTPServer.new(:Port=>0) p s.listeners s.listeners << TCPServer.new("127.0.0.1", "8080") # add a socket to listeners s.listen("127.0.0.1", 8081) # ditto. p s.listeners ' [2005-03-21 04:43:58] INFO WEBrick 1.3.1 [2005-03-21 04:43:58] INFO ruby 1.9.0 (2005-03-20) [i386-netbsd] [#, #] [#, #, #, #] -- gotoyuzo