Basically DRb.start_service should be used for either starting
client or server - which is strange already.
just to clarify: not really. all drb processes are servants.
neither server nor client exist separately. the definitions are
determines dynamically based on usage.
now run DRbServer.new("strange://usrl", object) starts drb server.
and @object = SRbObject.new(nil, "strange://url") creates object in
client
you have to start_service in both, perhaps with a front object and
perhaps not. when you look up and object using DRbObject service is
started for you iff it's not already on. the reason is that DRb
supports blocks. consider:
remote_array = DRbObject.new nil, "druby://localhost:1234"
remote_array.each do |element|
element.upcase!
end
if you think about this for a bit you'll see a complex interaction
between two servants. first, "remote_array.each" is going to make a
call on a remote object. that call is going to be passed a *block*
but, wait a minute, blocks cannot be marshaled so how does that
work? it doesn't. the block stays on the "client" and is executed
on that machine, on that cpu - but with a handle on remote "element"
objects. depending on how those objects are setup they might be
objects which are totally dumped/copied to the client and therefore
changes are going to be local *or* they may be proxies on remote
objects and destructive methods might actually change the remote
object behind the proxy. see DRbUndumped for more on this.
in any case the first step to understanding drb is doing away with
the idea of static servers and clients - in drb every machine can
potentially be both, sometimes within a given method. the
distribution contains a *ton* of examples:
cfp:~/build/ruby-1.8.6/sample/drb > ls
README.rd dbiff.rb dhasen.rb dqin.rb drbc.rb drbs-
acl.rb extserv_test.rb holderc.rb name.rb
rindac.rb ring_place.rb
README.rd.ja dcdbiff.rb dhasenc.rb dqlib.rb drbch.rb
drbs.rb gw_ct.rb holders.rb namec.rb
rindas.rb simpletuple.rb
darray.rb dchatc.rb dlogc.rb dqout.rb drbm.rb
drbssl_c.rb gw_cu.rb http0.rb old_tuplespace.rb
ring_echo.rb speedc.rb
darrayc.rb dchats.rb dlogd.rb dqueue.rb drbmc.rb
drbssl_s.rb gw_s.rb http0serv.rb rinda_ts.rb
ring_inspect.rb speeds.rb
which is a great place for people get started.
btw: favourite way to use drb is for ipc between two processes on the
same machine via:
process a:
DRb.start_service "druby:localhost:0",
some_object_that_acts_as_a_server
uri = DRb.uri
process b:
DRb.start_service "druby:localhost:0"
remote_object = DRbObject.new nil, uri
by starting service this way you basically setup drb to function
perfectly for ipc situations and accept connections on all
interfaces. it turns out that using remote/localhost objects for ipc
is a portable way to accomplish something that's generally non-
portable on windows/unix/whatever. recently i used this
http://drawohara.com/post/22540307
to solve a sticky windows signal issue - took only 4 or 5 lines of
code. really good stuff that drb ;-)
cheers.
a @
http://codeforpeople.com/