朝着MUD client,我使用的是telnet。em-simple_telnet.rb錯誤'pause_and_wait_for_result'
我試圖得到天氣like Apache does,但這個錯誤似乎可能是因爲我沒有正確使用em-simple_telnet API。
錯誤:
[email protected]:~/ruby$
[email protected]:~/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'
[email protected]:~/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會話:
[email protected]:~/ruby$
[email protected]:~/ruby$
[email protected]:~/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: [email protected] *
------------------------------------------------------------------------------
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.
[email protected]:~/ruby$
[email protected]:~/ruby$
只是爲了澄清,這裏沒有連接到MUD,這是一個用於測試和插圖目的的天氣服務。一旦我可以檢查天氣,然後我將繼續前進到有趣的遊戲:) – Thufir
我不知道這是如何相關的。天氣是一個telnet服務器嗎? – 7stud
是的,天氣服務是通過telnet,vt100據我所知。大多數CLI(Linux,Windows,Mac)上的telnet rainmaker.wunderground.com 3000'應該可以正常工作。 (同樣適用於MUD) – Thufir