From: M Mohr Date: 2002-09-10T00:31:36+09:00 Subject: Re: getting the IP address of the local machine Tom Sawyer writes: > oh and one other thing: how to find a free port? you have to search a free port with trial-and-error AFAIK. (maybe this can be done more elegant, I'm pretty new to ruby) : [schnipp] #!/usr/bin/env ruby require 'socket' # our port-range, in which we try to establish a listener ports = 2090..2100 # "define" these, to make them visible outside the iterator server = nil port = nil # search for port go = false ports.each { |port| printf("trying port %d\n", port) begin server = TCPServer.new('127.0.0.1', port) go = true break rescue Errno::EADDRINUSE # debug output $stderr.print "listen on #{port} failed: " + $! + "\n" end } # listen if (go) $stderr.printf("using port %d\n", port) while (go && (session=server.accept)) # # your server goes here # end end [schnapp] regards messju > On Mon, 2002-09-09 at 03:50, Tom Sawyer wrote: > > does anyone know how to get the IP address of the machine a ruby script > > is running on? > > > > -thanks > > > > -- > > tom sawyer, aka transami > > transami@transami.net > > > > > -- > tom sawyer, aka transami > transami@transami.net