em-simple_telnet.rb error 'pause_and_wait_for_result'

188 views Asked by At

Towards a MUD client, I'm using telnet.

I'm trying to get the weather like Apache does, but this error seems to, probably, be that I'm not using the em-simple_telnet API correctly.

error:

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$ 

code:

#!/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

Here's a telnet session with the weather service:

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: [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.
thufir@dur:~/ruby$ 
thufir@dur:~/ruby$ 
3

There are 3 answers

0
Thufir On

Patrik seems to have answered this, I think. Here's the results:

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$ 

code:

#!/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

Wasn't using the API properly, didn't realize.

1
Patrik On

Look at the example in the readme of em-simple_telnet. I guess you should wrap it in a call to EventMachine.run { … }.

Also, use keys like :host and :port in the options instead of "Host" and "Port".

4
7stud On

Okay, I read your first link. It says:

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.

Unfortunately, I think your telnet gem tries to do the telnet negotiations, and then times out when it doesn't get any response from the MUD. I'm not sure what it means to be a telnet client that doesn't follow the telnet protocol.

You might try connecting to the MUD server with sockets.