Programming Tutorials

(追記) (追記ここまで)

dRuby client/server mode sample program

By: Emiley J. in Ruby Tutorials on 2009年03月03日 [フレーム]

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
 URI="druby://localhost:8787"
 class TimeServer
 def get_current_time
 return Time.now
 end
 end
 # The object that handles requests on the server
 FRONT_OBJECT=TimeServer.new
 $SAFE = 1 # disable eval() and friends
 DRb.start_service(URI, FRONT_OBJECT)
 # Wait for the drb server thread to finish before exiting.
 DRb.thread.join

Client code

 require 'drb/drb'
 # The URI to connect to
 SERVER_URI="druby://localhost:8787"
 # 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.
 DRb.start_service
 timeserver = DRbObject.new_with_uri(SERVER_URI)
 puts timeserver.get_current_time



(追記) (追記ここまで)


Add Comment

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!
(追記) (追記ここまで)
(追記) (追記ここまで)

AltStyle によって変換されたページ (->オリジナル) /