⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 14 - proxying objects that can't be distributed.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
DRb.start_service  # The client needs to be a DRb service too.#---class MyLocalClass  include DRbUndumped  # The magic line.  All objects of this type are proxied.  # ...end# ... OR ...my_local_object.extend DRbUndumped  # Proxy just this object.#---#!/usr/bin/ruby# hello_server.rbrequire 'drb'# a simple greeter classclass HelloService  def hello(in_stream, out_stream)    out_stream.puts 'What is your name?'    name = in_stream.gets.strip    out_stream.puts "Hello #{name}."  endend# start up DRb with URI and object to shareDRb.start_service('druby://localhost:61676', HelloService.new)DRb.thread.join  # wait on DRb thread to exit...#---#!/usr/bin/ruby# hello_client.rbrequire 'drb'# fetch service object and ask it to greet us...hello_service = DRbObject.new_with_uri('druby://localhost:61676')hello_service.hello($stdin, $stdout)#---#!/usr/bin/ruby# hello_client2.rbrequire 'drb'DRb.start_service  # make sure client can serve proxy objects...# and request that the streams be proxied$stdin.extend  DRbUndumped$stdout.extend DRbUndumped# fetch service object and ask it to greet us...hello_service = DRbObject.new_with_uri('druby://localhost:61676')hello_service.hello($stdin, $stdout)#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -