Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | dRubyを試してみる

概要

dRubyを試してみる

サンプルコード(Server)

require 'drb/drb'

class Server
  def initialize(stream=$stdout)
    @stream = stream
  end

  def puts(str)
    @stream.puts("Hello dRuby '#{str}'")
  end
end

uri = ARGV.shift
DRb.start_service(uri, Server.new)
puts DRb.uri
sleep

サンプルコード(Client)

require 'drb/drb' 
there = DRbObject.new_with_uri('druby://localhost:12345')
there.puts "from Client"

動作確認

サーバー側

$ ruby server.rb druby://localhost:12345
druby://localhost:12345
Hello dRuby 'from Client'

クライアント側

ruby client.rb