Ruby分布式编程与测试调试实战
1. 代理不可分布式对象
在分布式编程中,有时候会遇到无法直接分布的对象,比如本地资源。以一个简单的DRb服务为例,服务端代码如下:
class HelloService
def hello(in_stream, out_stream)
puts "Enter your name: "
name = in_stream.gets.chomp
out_stream.puts "Hello #{name}."
end
end
# start up DRb with URI and object to share
DRb.start_service('druby://localhost:61676', HelloService.new)
DRb.thread.join # wait on DRb thread to exit...
客户端代码最初尝试这样连接:
#!/usr/bin/ruby
# hello_client.rb
require 'drb'
# fetch service object and ask it to greet us...
hello_service = DRbObject.new_with_uri('druby://localhost:61676')
hello_service.hello($stdin, $stdout)
但这样会产生错误,因为 $stdin 和
超级会员免费看
订阅专栏 解锁全文
850

被折叠的 条评论
为什么被折叠?



