From: Eric Hodel Date: 2005-07-18T05:11:30+09:00 Subject: Re: Cheapest ping possible On 17 Jul 2005, at 07:20, Daniel Berger wrote: > Matthew Margolis wrote: > >> I know about ruby ping >> (http://www.ruby-doc.org/stdlib/libdoc/ping/rdoc/index.html). Has >> anyone used this library for a lot of concurrent pings? Are there >> any >> better solutions out there for what I need? > > I use net-ping, available on the RAA. I use that because, well, I > wrote it. :) > > Yes, threads are probably the way to go: > > require "net/ping" > include Net > > threads = [] threads = ThreadGroup.new > hosts.each{ |host_to_ping| > threads << Thread.new(host_to_ping){ |host| threads.add Thread.new(host_to_ping){ |host| > ping_obj = PingTCP.new(host) # or UDP, or whatever you prefer > unless ping_obj.ping? > # Failed to ping 'host' > end > } > } > > threads.each{ |t| t.join } threads.list.each { |t| t.join } A ThreadGroup doesn't hang on to dead threads, so if a thread finishes it will be garbage collected. -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04