迈向MUD client,我正在使用telnet。
我正在尝试获取天气like Apache does,但这个错误似乎可能是因为我没有正确使用em-simple_telnet API。
错误:
thufir@dur:~/ruby$
thufir@dur:~/ruby$ ruby weather.rb
{"host"=>"rainmaker.wunderground.com", "port"=>3000}
/home/thufir/.rvm/gems/ruby-2.0.0-p247/gems/em-simple_telnet-0.0.14/lib/em-simple_telnet.rb:712:in `pause_and_wait_for_result': EventMachine::Protocols::SimpleTelnet::ConnectionFailed (EventMachine::Protocols::SimpleTelnet::ConnectionFailed)
from /home/thufir/.rvm/gems/ruby-2.0.0-p247/gems/em-simple_telnet-0.0.14/lib/em-simple_telnet.rb:246:in `connect'
from /home/thufir/.rvm/gems/ruby-2.0.0-p247/gems/em-simple_telnet-0.0.14/lib/em-simple_telnet.rb:191:in `block in new'
thufir@dur:~/ruby$
代码:
#!/usr/bin/env ruby
require 'rubygems'
require 'em-simple_telnet'
require 'yaml'
require 'pry'
require 'pp'
opts = YAML.load_file('params.yml')
pp opts
EM::P::SimpleTelnet.new(opts) do |host|
puts host.cmd("ls -la")
end
这是与气象服务的telnet会话:
thufir@dur:~/ruby$
thufir@dur:~/ruby$
thufir@dur:~/ruby$ telnet rainmaker.wunderground.com 3000
Trying 38.102.137.140...
Connected to rainmaker.wunderground.com.
Escape character is '^]'.
------------------------------------------------------------------------------
* Welcome to THE WEATHER UNDERGROUND telnet service! *
------------------------------------------------------------------------------
* *
* National Weather Service information provided by Alden Electronics, Inc. *
* and updated each minute as reports come in over our data feed. *
* *
* **Note: If you cannot get past this opening screen, you must use a *
* different version of the "telnet" program--some of the ones for IBM *
* compatible PC's have a bug that prevents proper connection. *
* *
* comments: jmasters@wunderground.com *
------------------------------------------------------------------------------
Press Return to continue:
Press Return for menu
or enter 3 letter forecast city code-- dca
Weather Conditions at 12:27 AM EDT on 29 Aug 2013 for Washington, DC.
Temp(F) Humidity(%) Wind(mph) Pressure(in) Weather
========================================================================
75 89% NE at 7 29.85 Overcast
Forecast for Washington, MD
1030 PM EDT Wed Aug 28 2013
.Rest of tonight...Cloudy. Scattered showers late this evening...
then isolated showers. Patchy fog. Lows around 70. South winds
around 5 mph...becoming east. Chance of rain 50 percent.
.Thursday...Mostly cloudy in the morning...then becoming mostly
sunny. Patchy fog in the morning. Scattered sprinkles. Highs in the
lower 80s. Northeast winds 5 to 10 mph.
.Thursday night...Partly cloudy. Scattered sprinkles in the evening.
Lows in the mid 60s. East winds around 5 mph...becoming north after
midnight.
.Friday...Mostly sunny. Highs in the lower 80s. North winds around
5 mph...becoming southeast in the afternoon.
.Friday night...Partly cloudy in the evening...then becoming mostly
cloudy. Lows in the upper 60s. South winds around 5 mph.
.Saturday...Partly sunny. Highs in the mid 80s.
.Saturday night...Mostly cloudy. Lows in the upper 60s.
Press Return to continue, M to return to menu, X to exit: x
Connection closed by foreign host.
thufir@dur:~/ruby$
thufir@dur:~/ruby$
答案 0 :(得分:1)
好的,我看了你的第一个链接。它说:
MUD客户端是用于连接MUD的计算机应用程序 多人在线游戏类型。通常,MUD客户端非常 缺少VT100终端仿真的基本telnet客户端 执行telnet谈判的能力。
不幸的是,我认为你的telnet gem尝试进行telnet协商,然后在没有得到MUD的任何响应时超时。我不确定成为不遵循telnet协议的telnet客户端意味着什么。
您可以尝试使用套接字连接到MUD服务器。
答案 1 :(得分:1)
请看em-simple_telnet自述文件中的示例。我想你应该把它包装在对EventMachine.run {...}的调用中。
此外,在选项中使用键如:host和:port而不是“Host”和“Port”。
答案 2 :(得分:0)
Patrik似乎已经回答了这个问题,我想。结果如下:
thufir@dur:~/ruby$
thufir@dur:~/ruby$ ruby weather.rb
{"host"=>"rainmaker.wunderground.com", "port"=>3000}
{:host=>"rainmaker.wunderground.com", :port=>"3000"}
"opts and opts2 are different, didn't realize that"
"seems to connect, just not sure yet how print server output"
SimpleTelnet: EventMachine reactor had been started independently. Won't stop it automatically.
#<EventMachine::Protocols::SimpleTelnet:0x9c25408
@check_input_buffer_timer=nil,
@connection_state=:connected,
@fiber_resumer=
#<Proc:0x9c2537c@/home/thufir/.rvm/gems/ruby-2.0.0-p247/gems/em-simple_telnet-0.0.14/lib/em-simple_telnet.rb:374 (lambda)>,
@input_buffer="",
@input_rest="",
@last_command=nil,
@logged_in=2013-08-29 06:50:13 -0700,
@signature=2,
@telnet_options=
{:host=>"rainmaker.wunderground.com",
:port=>"3000",
:prompt=>/[$%#>] \z/n,
:connect_timeout=>3,
:timeout=>10,
:wait_time=>0,
:bin_mode=>false,
:telnet_mode=>true,
:output_log=>nil,
:command_log=>nil,
:login_prompt=>/[Ll]ogin[: ]*\z/n,
:password_prompt=>/[Pp]ass(?:word|phrase)[: ]*\z/n,
:username=>nil,
:password=>nil,
:SGA=>false,
:BINARY=>false},
@wait_time_timer=nil>
^C/home/thufir/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run_machine': Interrupt
from /home/thufir/.rvm/gems/ruby-2.0.0-p247/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
from weather.rb:9:in `<main>'
thufir@dur:~/ruby$
thufir@dur:~/ruby$
代码:
#!/usr/bin/env ruby
require 'rubygems'
require 'em-simple_telnet'
require 'yaml'
require 'pry'
require 'pp'
EventMachine.run do
opts2 = YAML.load_file('params.yml')
pp opts2
opts = {
host: "rainmaker.wunderground.com",
port: "3000",
}
pp opts
pp "opts and opts2 are different, didn't realize that"
pp "seems to connect, just not sure yet how print server output"
EM::P::SimpleTelnet.new(opts) do |host|
pp host
end
end
没有正确使用API,没有意识到。