From: "Stephan Kämper" Date: 2004-01-04T09:01:47+09:00 Subject: More from using DRb and observers... Andre Nathan wrote: > Have a look at the thread starting at ruby-talk:88698. > Hi all, Andre, thanks for the link to the earlier discussion. Now the 'compressed' notifier looks like this... require 'drb' require 'drb/observer' class Notifier include Observable include DRb::DRbUndumped def change( i ) puts "Changing: #{'%2d' % i}" changed( true ) notify_observers( Time.now, i ) end end DRb.start_service( 'druby://tao:4711', Notifier.new ) puts DRb.uri DRb.thread.join ....and the client like that: require 'drb' class Client include DRb::DRbUndumped def initialize( observed ) observed.add_observer( self ) end def update( *args ) puts "!!!" p *args end end DRb.start_service notifier = DRbObject.new( nil, 'druby://tao:4711' ) d = Client.new( notifier ) notifier.change( rand( 10 ) ) Now, running both programs once works fine. For Notifier: [979] stk@tao ~/devel/util: ruby Notifier.rb druby://tao:4711 Changing: 4 For Client: [974] stk@tao ~/devel/util: ruby Client.rb !!! Sun Jan 04 00:32:53 CET 2004 6 Great! And thanks again for the help! Unfortunately starting the client a second time it get an error I (partially) don't understand. The Server output continues with: Changing: 1 The Client output is this: Sun Jan 04 00:40:11 CET 2004 4 [974] stk@tao ~/devel/util: ruby Client.rb (druby://tao:4711) /usr/local/lib/ruby/1.8/drb/drb.rb:705:in `open': druby://tao:33324 - # (DRb::DRbConnError) from (druby://tao:4711) /usr/local/lib/ruby/1.8/drb/drb.rb:698:in `each' from (druby://tao:4711) /usr/local/lib/ruby/1.8/drb/drb.rb:698:in `open' from (druby://tao:4711) /usr/local/lib/ruby/1.8/drb/drb.rb:1084:in `initialize' from (druby://tao:4711) /usr/local/lib/ruby/1.8/drb/drb.rb:1067:in `new' from (druby://tao:4711) /usr/local/lib/ruby/1.8/drb/drb.rb:1067:in `open' from (druby://tao:4711) /usr/local/lib/ruby/1.8/drb/drb.rb:1014:in `method_missing' from (druby://tao:4711) /usr/local/lib/ruby/1.8/observer.rb:185:in `notify_observers' from (druby://tao:4711) /usr/local/lib/ruby/1.8/observer.rb:184:in `each' from (druby://tao:4711) /usr/local/lib/ruby/1.8/observer.rb:184:in `notify_observers' from (druby://tao:4711) Notifier.rb:11:in `change' from Client.rb:19 [974] stk@tao ~/devel/util: Now, why does it say >>> druby://tao:33324 <<< in the 1st line of th output? And how can I stop this? BTW, 'ruby -v' yields: ruby 1.8.1 (2003-12-25) [i686-linux]. Happy rubying! Stephan