From: Joel VanderWerf Date: 2004-04-25T04:34:02+09:00 Subject: Re: Playing with sockets... Hal Fulton wrote: > Hal Fulton wrote: > >> I wonder: How hard is it to write a server to which one would connect >> with telnet? > > > To answer my own question: Frightfully easy. > > require 'socket' > port = 8023 > server = TCPServer.new('localhost', port) > session = server.accept > while cmd = session.gets.chomp > break if cmd =~ /quit/ > session.print "You said: '#{cmd}'\n" > end > session.print "Bye!" > session.close > > > It's nice when things just work. And if you want to handle multiple requests, it's easy to thread this server. See sample/tsvr.rb in the ruby distribution.