Skip to content

Instantly share code, notes, and snippets.

@gnarg
Created October 25, 2012 21:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnarg/3955498 to your computer and use it in GitHub Desktop.
Save gnarg/3955498 to your computer and use it in GitHub Desktop.
drb socket pair protocol interface
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