1=begin
2 distributed Ruby --- dRuby Sample Server
3 	Copyright (c) 1999-2000,2002 Masatoshi SEKI
4=end
5
6=begin
7 How to play.
8
9 Terminal 1
10 | % ruby drbs.rb
11 | druby://yourhost:7640
12
13 Terminal 2
14 | % ruby drbc.rb druby://yourhost:7640
15 | "hello"
16 | ....
17
18=end
19
20require 'drb/drb'
21
22class DRbEx
23  include DRbUndumped
24
25  def initialize
26    @hello = 'hello'
27  end
28
29  def hello
30    cntxt = Thread.current['DRb']
31    if cntxt
32      p cntxt['server'].uri
33      p cntxt['client'].peeraddr
34    end
35    Foo::Unknown.new
36  end
37
38  def err
39    raise FooError
40  end
41
42  def sample(a, b, c)
43    a.to_i + b.to_i + c.to_i
44  end
45end
46
47class Foo
48  class Unknown
49  end
50end
51
52class FooError < RuntimeError
53end
54
55if __FILE__ == $0
56  DRb.start_service(ARGV.shift || 'druby://:7640', DRbEx.new)
57  puts DRb.uri
58  Thread.new do
59    sleep 10
60    DRb.stop_service
61  end
62  DRb.thread.join
63end
64
65