dRuby client/server mode sample program

By: Emiley J.  

This illustrates setting up a simple client-server drb system. Run the server and client code in different terminals, starting the server code first.

Server code

  require 'drb/drb'

  # The URI for the server to connect to

  class TimeServer

    def get_current_time
      return Time.now


  # The object that handles requests on the server

  $SAFE = 1   # disable eval() and friends

  DRb.start_service(URI, FRONT_OBJECT)
  # Wait for the drb server thread to finish before exiting.

Client code

  require 'drb/drb'

  # The URI to connect to

  # Start a local DRbServer to handle callbacks.
  # Not necessary for this small example, but will be required
  # as soon as we pass a non-marshallable object as an argument
  # to a dRuby call.

  timeserver = DRbObject.new_with_uri(SERVER_URI)
  puts timeserver.get_current_time

Archived Comments

1. likevk_ufyz
View Tutorial          By: likevk_spzg at 2017-04-21 16:54:56

Most Viewed Articles (in Ruby )

Latest Articles (in Ruby)

Comment on this tutorial