From: Lars Christensen Date: 2008-06-30T21:17:16+09:00 Subject: Re: Why can't I return "Threads.list" Array in DRb? On Jun 29, 7:00 pm, Iñaki Baz Castillo wrote: > El Domingo, 29 de Junio de 2008, Iñaki Baz Castillo escribió: > > El Domingo, 29 de Junio de 2008, Iñaki Baz Castillo escribió: > > > but instead of an Array object I get a DRb::DRbObject, and in each call > > > to this method I get a different "id": > > Well, I am understanding that if DRb server return an object unknown for the > DRb client, the the only way the client hast to use/show it is as raw value, > is it? It seems more like a situation where DRb detects that the return object (the Array) is not fully serializable (contains non- derializable objects), and hence it returns a "server reference" or "proxy object" for the object instead. Whenever you invoke method on the proxy object, they are invoked on the server. This is really the beauty of DRb: Objects that can't be marshalled / serialized, become remote objects automatically. You can even 'yield' to blocks on the client, which is what happens when you "puts" the array. Here's a simpler example: class Thing include DRb::DRbUndumped # make sure instance are not marshalled and transferred def each puts "each called on server" 3.times { |i| yield(i) } end end class Server def create_thing Thing.new end end DRb::start_service("druby://:12000", Server.new) DRb.thread.join And a client: DRb.start_service remoteServer = DRb::DRbObject.new(nil, "druby://localhost:12000") remoteThing = remoteServer.create_thing remoteThing.each { |i| p i } The 'remoteThing' becomes a DRb::DRbObject which serves as a proxy to the Thing object on the server. Thing#each is actally run on the server and yields back to the block on the client. Lars