我正在使用dRuby而且我试图以这种方式读取文件:
服务器代码:
require 'drb/drb'
URI="druby://0.0.0.0:8787"
class TimeServer
def leer(nombre)
puts nombre
lines = []
File.open(nombre, "r") do |file|
file.each_line do |line|
lines << line
end
end
return lines
end
end
FRONT_OBJECT=TimeServer.new
$SAFE = 1
DRb.start_service(URI, FRONT_OBJECT)
DRb.thread.join
客户代码:
SERVER_URI="druby://192.168.56.1:8787"
DRb.start_service
timeserver = DRbObject.new_with_uri(SERVER_URI)
puts timeserver.leer("aname")
这是客户端控制台上的错误:
C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:570:in `load': connection closed (DRb::DRbConnError)
from C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:632:in `recv_reply'
from C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:918:in `recv_reply'
from C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:1197:in `send_message'
from C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:1088:in `block (2 levels) in method_missing'
from C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:1172:in `open'
from C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:1087:in `block in method_missing'
from C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:1105:in `with_friend'
from C:/Ruby193/lib/ruby/1.9.1/drb/drb.rb:1086:in `method_missing'
from C:/Users/federico/Downloads/RUBY/PROGRAMITAS/pruebaclien.rb:5:in `<main>'
该程序在服务器的控制台中打印&#34; nombre&#34;的值,但在到达File.open(nombre, "r")
时崩溃。