Created
August 24, 2012 11:51
-
-
Save addisaden/3449727 to your computer and use it in GitHub Desktop.
Simple DRb Client + Echoserver (localhost)
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
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) | |
} |
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
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