question DRb class definition share or not share

J

Jack

Just go through ruby cookbook & only tutorial for any DRb stuff. But I
need help explain below example that I don't understand why DRbUndump
is not needed. On some of the samples, I see class definition is
defined in a separate file and was 'require' by both client & server.
But in this case, the class definition is embedded in server side
code.

The below code works. I would think variable 'ro' in client represent
a proxy. So on the server side, the class definiton probably need to
include DRbUndump. Can anyone explain to my confusion?

# client
require 'drb'
DRb.start_service
ro = DRbObject.new(nil, 'druby://localhost:7777')
print ro.songname

#server
#!/usr/local/bin/ruby
require 'drb'

class SongNameServer
def initialize(str)
@filename = str
end
def songname
f = File.new(@filename)
return f.readline
end
end

DRb.start_service("druby://localhost:7777", SongNameServer.new("/tmp/
songname"))
puts DRb.uri

DRb.thread.join
 
E

Eric Hodel

Just go through ruby cookbook & only tutorial for any DRb stuff. But I
need help explain below example that I don't understand why DRbUndump
is not needed. On some of the samples, I see class definition is
defined in a separate file and was 'require' by both client & server.
But in this case, the class definition is embedded in server side
code.

The below code works. I would think variable 'ro' in client represent
a proxy. So on the server side, the class definiton probably need to
include DRbUndump. Can anyone explain to my confusion?

This is exactly right. DRbUndumped forces the creation of a proxy
object on the client.
 
J

Jack

This is exactly right. DRbUndumped forces the creation of a proxy
object on the client.

Thanks Eric, it is much clear to me now! The recipe 16.10 of ruby
cookbook include class definition on both client and server that was
not actually required on client side. From other examples, it is clear
now when I need it. I think I need to watch out the parameters pass to
the method.

Your online tutorial also very helpful, BTW, thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

drb load limit 3
DRB class in array 7
DRB Program Error 2
trying to get drb to work ... 0
drb application in bots 0
Append (<<) to Array attributes of DRb objects? 5
DRB ruby ACL problems 1
Ruby Tk and DRb 0

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top