Drb

From RubySpec

Jump to: navigation, search

drb is a distributed ruby library. The following code snippet shows sample usage of the distributed ruby library.

First, the DRb server:

 require 'drb'
 class Server
  def initialize
   @store = Array.new
  end
 #process the information from client
  def reverseit(*args)
   args.each {|a| @store.push(a.reverse)}
   @store
  end
 end
 server = Server.new
 DRb.start_service('druby://localhost:9000',server)
 DRb.thread.join


Next, the DRb client:

 require 'drb'
 ary = Array.new
 DRb.start_service
 o = DRbObject.new(nil,'druby://localhost:9000')
 ary = o.reverse_it("Hello","World","GoodBye","World")
 ary.each do |elem|
  puts elem
 end
Personal tools