Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created March 12, 2014 20:04
Show Gist options
  • Save Mon-Ouie/9515174 to your computer and use it in GitHub Desktop.
Save Mon-Ouie/9515174 to your computer and use it in GitHub Desktop.
require 'drb'
host = "localhost"
port = 9876
uri = "druby://#{host}:#{port}"
10.times do
local_ip = UDPSocket.open {|s| s.connect(host, 1); s.addr.last}
DRb.start_service "druby://#{local_ip}:0"
obj = DRbObject.new(nil, uri)
puts "Our waiter is #{obj.name}"
obj.thread = Thread.current
sleep
puts "Goodbye!"
DRb.stop_service
end
require 'drb'
host = "0.0.0.0"
port = 9876
uri = "druby://#{host}:#{port}"
Waiter = Struct.new(:name, :thread)
%w[John Dylan Bob Sylvia Anna].cycle do |name|
DRb.start_service uri, w=Waiter.new(name)
puts "#{w.name} is waiting"
sleep 0.1 until w.thread
puts "got client!"
sleep 1
w.thread.run
DRb.stop_service
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment