From: Robert Klemme Date: 2004-06-11T02:58:38+09:00 Subject: Re: a __real__ drb question Did I say I included the source code? Darn... robert #!/usr/bin/ruby require 'drb/drb' URI="druby://localhost:8787" module Kernel private def tputs(*a) th = Thread.current.inspect a.each do |arg| puts "#{th}: #{a}" end end end class Foo def test(*a) tputs "#{self.inspect}: ++++ #{a.inspect}" sleep( 1 + rand( 3 ) ) Thread.pass tputs "#{self.inspect}: ---- #{a.inspect}" end end mode = ARGV.shift || 'server' time = ARGV.shift || 60 case mode when 'server' obj = Foo.new drb = DRb.start_service URI, obj puts "DRB started at #{URI}" sleep time puts "Stopping DRB..." drb.stop_service DRb.thread.join puts "DRB terminated" when 'client' # a single client DRb.start_service obj = DRbObject.new_with_uri(URI) 10.times do |i| puts i obj.test i end when 'multi' # multiple clients DRb.start_service threads = [] 5.times do |th| threads << Thread.new(th) do |id| o = DRbObject.new_with_uri(URI) 5.times do |i| puts "client #{id}: #{i}" o.test i end end end threads.each {|t| t.join} end