From: Mike Stok Date: 2002-09-10T01:11:43+09:00 Subject: Re: getting the IP address of the local machine In article <873csj2o6x.fsf@pharao.lammfellpuschen.de>, M Mohr wrote: > 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) : You can let the system find one for you by using 0 as a port e.g. [mike@ratdog rubicon]$ irb irb(main):001:0> require 'socket' true irb(main):002:0> s1 = TCPServer::new('localhost', 0) # irb(main):003:0> s2 = TCPServer::new('localhost', 0) # irb(main):004:0> s1.addr ["AF_INET", 54458, "localhost.localdomain", "127.0.0.1"] irb(main):005:0> s2.addr ["AF_INET", 54459, "localhost.localdomain", "127.0.0.1"] Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA