2013-08-29 27 views
0

朝着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$ 

回答

1

好吧,我看了你的第一個鏈接。它說:

A MUD client is a computer application used to connect to a MUD, a type of multiplayer online game. Generally, a MUD client is a very basic telnet client that lacks VT100 terminal emulation and the capability to perform telnet negotiations.

不幸的是,我覺得你的telnet寶石試圖做的telnet談判,然後超時時,它不會從MUD任何迴應。我不確定成爲不遵循telnet協議的telnet客戶端意味着什麼。

您可以嘗試使用套接字連接到MUD服務器。

+0

只是爲了澄清,這裏沒有連接到MUD,這是一個用於測試和插圖目的的天氣服務。一旦我可以檢查天氣,然後我將繼續前進到有趣的遊戲:) – Thufir

+0

我不知道這是如何相關的。天氣是一個telnet服務器嗎? – 7stud

+0

是的,天氣服務是通過telnet,vt100據我所知。大多數CLI(Linux,Windows,Mac)上的telnet rainmaker.wunderground.com 3000'應該可以正常工作。 (同樣適用於MUD) – Thufir

1

看看em-simple_telnet自述文件中的例子。我想你應該把它包裝在EventMachine.run {...}的調用中。

此外,在選項中使用諸如主機和端口之類的鍵而不是「主機」和「端口」。

+0

我認爲這是答案,請使用您的答案查看我的答案。 – Thufir

0

Patrik似乎已經回答了這個問題,我想。這裏的結果:

[email protected]:~/ruby$ 
[email protected]:~/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:[email protected]/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>' 

[email protected]:~/ruby$ 
[email protected]:~/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​​正常,並沒有意識到。