Created
October 25, 2012 21:21
-
-
Save gnarg/3955498 to your computer and use it in GitHub Desktop.
drb socket pair protocol interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeServer | |
def get_current_time | |
Time.now | |
end | |
end | |
################ | |
URI = 'druby://localhost:8787' | |
DRb.start_service(URI, TimeServer.new) | |
pids = [] | |
pids << Process.fork do | |
timeserver = DRbObject.new_with_uri(URI) | |
puts "#{Process.pid} #{timeserver.get_current_time}" | |
end | |
pids << Process.fork do | |
timeserver = DRbObject.new_with_uri(URI) | |
puts "#{Process.pid} #{timeserver.get_current_time}" | |
end | |
pids.each{|pid| Process.wait(pid) } | |
################ | |
# DRb.start_service('drbsocketpair:', TimeServer.new) | |
# pids = [] | |
# s0 = DRbSocketPair.create_socket | |
# pids << Process.fork do | |
# timeserver = DRbObject.new_with_uri('drbsocketpair:s0') | |
# puts "#{Process.pid} #{timeserver.get_current_time}" | |
# end | |
# s0.close | |
# s1 = DRbSocketPair.create_socket | |
# pids << Process.fork do | |
# timeserver = DRbObject.new_with_uri('drbsocketpair:s1') | |
# puts "#{Process.pid} #{timeserver.get_current_time}" | |
# end | |
# s1.close | |
# pids.each{|pid| Process.wait(pid) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment