Provides telnet client functionality.

This class derived from the Net::Telnet class in Ruby's standard library. It was developed with simplicity in mind. It tries to hide the complexity that normally comes with asynchronous programming using the Fiber class found in Ruby 1.9.


The telnet protocol allows a client to login remotely to a user account on a server and execute commands via a shell. The equivalent is done by creating a EventMachine::Protocols::SimpleTelnet instance with the :host option set to your host along with a block which defines the task to be done on the host. Inside the task you can issue one or more #cmd calls. After the block is executed, #close is automatically called.

This class can also be used to connect to non-telnet services, such as SMTP or HTTP. In this case, you normally want to provide the :port option to specify the port to connect to, and set the :telnet_mode option to false to prevent the client from attempting to interpret telnet command sequences. Generally, #login will not work with other protocols, and you have to handle authentication yourself.


EventMachine.run do

  opts = {
    host: "localhost",
    username: "user",
    password: "secret",

  EM::P::SimpleTelnet.new(opts) do |host|
    # already logged in
    puts host.cmd("ls -la")


There are a large number of RFCs relevant to the Telnet protocol. RFCs 854-861 define the base protocol. For a complete listing of relevant RFCs, see www.omnifarious.org/~hopper/technical/telnet-rfc.html