Skip to content

Instantly share code, notes, and snippets.

@addisaden
Created August 24, 2012 11:51
Show Gist options
  • Save addisaden/3449727 to your computer and use it in GitHub Desktop.
Save addisaden/3449727 to your computer and use it in GitHub Desktop.
Simple DRb Client + Echoserver (localhost)
require "drb/drb"
print "port: "
port = gets.strip
raise "port is no valid" unless /^\d+$/ =~ port
there = DRbObject.new_with_uri("druby://localhost:#{ port }")
loop {
print "send message: "
there.puts(gets.strip)
}
require "drb/drb"
class EchoServer
def initialize(stream=$stdout)
@stream = stream
DRb.start_service('druby://localhost:0', self)
@uri = DRb.uri
puts "HW-Server started at #{ @uri }"
tnow()
DRb.thread.join()
end
def puts(str)
@stream.puts(str)
end
private
def tnow
Thread.start {
loop {
puts ">>> #{Time.now} <<<"
sleep 10
}
}.join()
end
end
EchoServer.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment