On Jul 31, 2006, at 9:27 PM, Dale Martenson wrote:

> I thought about writing my own using GServer and IO.popen, but before
> embark on that I wanted to avoid re-inventing the wheel.

It's super easy to get something going with GServer, but my new  
favorite is actually EventMachine.  I just built a server application  
with that library last week and it really rocks.  Definitely look it  
over.

If all you need is bare bones Telnet handling you can use something  
like this:

     def parse_telnet(data)                # minimal Telnet
       data.gsub!(/([^\015])\012/, "\\1")  # ignore bare LFs
       data.gsub!(/\015\0/, "")            # ignore bare CRs
       data.gsub!(/\0/, "")                # ignore bare NULs

       while data.index("\377")            # parse Telnet codes
         if data.sub!(/(^|[^\377])\377[\375\376](.)/, "\\1")
           # answer DOs and DON'Ts with WON'Ts
           send_data("\377\374#{$2}")
         elsif data.sub!(/(^|[^\377])\377[\373\374](.)/, "\\1")
           # answer WILLs and WON'Ts with DON'Ts
           send_data("\377\376#{$2}")
         elsif data.sub!(/(^|[^\377])\377\366/, "\\1")
           # answer "Are You There" codes
           send_data("Still here, yes.")
         elsif data.sub!(/(^|[^\377])\377\364/, "\\1")
           # do nothing - ignore IP Telnet codes
         elsif data.sub!(/(^|[^\377])\377[^\377]/, "\\1")
           # do nothing - ignore other Telnet codes
         elsif data.sub!(/\377\377/, "\377")
           # do nothing - handle escapes
         end
       end

       data
     end

Maybe you could expand that to meet your needs.

Hope that helps.

James Edward Gray II