telnet拉数据超时问题

时间:2011-12-30 04:55:49

标签: ruby timeout telnet

这是我通过普通telnet或甚至通过ruby telnet获得的数据。我不知道如何告诉它在END DATABASE

时退出
# Manual telnet method
Trying 10.1.1.12...
Connected to 10.1.1.12.
Escape character is '^]'.
F#1=
F#1=
BEGIN DATABASE

2011-12-29 13:53,1,Hefer Meal,240,247,Z88,1,1
2011-12-29 13:53,1,Vegetable Oil,30,59,Z88,1,1
2011-12-29 13:55,2,Vegetable Oil,100,106,530,1,1
2011-12-29 13:55,2,Steer Meal,800,809,530,1,1
2011-12-29 13:56,3,Vegetable Oil,150,153,530,1,0
2011-12-29 13:57,3,Steer Meal,1200,1203,530,1,0
2011-12-29 14:30,4,Vegetable Oil,17,18,210,1,1
2011-12-29 14:31,4,Liquid Starter,388,394,210,1,1
2011-12-29 14:39,5,Hefer Meal,1200,1227,Z88,1,2
2011-12-29 14:40,6,Hefer Meal,1200,1240,Z88,1,2
2011-12-29 14:41,7,Hefer Meal,1200,1207,Z88,1,0
2011-12-29 14:43,8,Hefer Meal,1200,1286,Z88,1,2
2011-12-29 14:46,9,Vegetable Oil,115,122,530,1,1
2011-12-29 14:50,9,Steer Meal,920,950,530,1,1
2011-12-29 14:56,10,Vegetable Oil,47,48,312,1,0
2011-12-29 14:57,10,Steer Meal,237,261,312,1,1
2011-12-29 14:58,10,Liquid Starter,389,394,312,1,1
END DATABASE

这是我的代码:

#!/usr/local/bin/ruby
require 'net/telnet'
localhost = Net::Telnet::new("Host" => "10.1.1.12", "Timeout" => 10, "Port" => 10001) { |resp| print "===> " + resp }
localhost.cmd("F#1=") do |data| 
   print data
end

当它运行时,它输出所有数据然后等待和错误:

/usr/lib/ruby/1.8/net/telnet.rb:557:in `waitfor': timed out while waiting for more data (Timeout::Error)

老实说我甚至不确定从哪里开始,我已经查看this页面了解更多关于如何处理它的信息,但我找不到任何东西。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您似乎在这里使用非标准的telnet服务器。初始化时请将“Telnetmode”设置为false。

localhost = Net::Telnet::new("Host" => "10.1.1.12", "Telnetmode" => false, "Timeout" => 10, "Port" => 10001) { |resp| print "===> " + resp }