* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / sample / drb / drbs.rb
blobb76e283c80c197124837b69772ba7141ddf7a51a
1 =begin
2  distributed Ruby --- dRuby Sample Server
3         Copyright (c) 1999-2000,2002 Masatoshi SEKI 
4 =end
6 =begin
7  How to play.
9  Terminal 1
10  | % ruby drbs.rb 
11  | druby://yourhost:7640
13  Terminal 2
14  | % ruby drbc.rb druby://yourhost:7640
15  | "hello"
16  | ....
18 =end
20 require 'drb/drb'
22 class DRbEx
23   include DRbUndumped
25   def initialize
26     @hello = 'hello'
27   end
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
38   def err
39     raise FooError
40   end
42   def sample(a, b, c)
43     a.to_i + b.to_i + c.to_i
44   end
45 end
47 class Foo
48   class Unknown
49   end
50 end
52 class FooError < RuntimeError
53 end
55 if __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
63 end