From: Enrico Pilotto Date: 2013-07-16T22:35:39+09:00 Subject: Call a method with block on distributed object (drb) Hi. I've the follow class for a distributed object: class Counter def initialize(i = 0) @index = i end def increment @index += 1 end def current return @index end def each(n = 1) threads = [] n.times do threads << Thread.new do yield(self.current) end end threads.map(&:join) end end Now the server: require 'drb' require './counter.rb' DRb.start_service('druby://127.0.0.1:9000', Counter.new) puts "Wordlist server running at #{DRb.uri}" trap('SIGINT') { DRb.stop_service } DRb.thread.join And the client: require 'drb' c = DRbObject.new_with_uri('druby://127.0.0.1:9000') c.each(8) do |i| puts i end I run the server (ok) and then the client and I get the follow error: /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1687:in `current_server': DRb::DRbServerNotFound (DRb::DRbConnError) from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1756:in `to_id' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1071:in `initialize' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:647:in `new' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:647:in `make_proxy' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:564:in `rescue in dump' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:561:in `dump' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:610:in `send_request' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:921:in `send_request' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1221:in `send_message' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1110:in `block (2 levels) in method_missing' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1197:in `open' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1109:in `block in method_missing' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1128:in `with_friend' from /Users/pioz/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/drb/drb.rb:1108:in `method_missing' from client.rb:5:in `
' Why? If I change the client in this way: require 'drb' require 'mechanize' c = DRbObject.new_with_uri('druby://127.0.0.1:9000') threads = [] 8.times do threads << Thread.new do puts c.current end end threads.map(&:join) all works fine. Any idea or help? -- Posted via http://www.ruby-forum.com/.