From: Massimiliano Mirra <list / chromatic-harp.com>
Subject: [ruby-talk:24526] Re: TCPServer example in PP book
Date: Thu, 8 Nov 2001 00:17:47 +0900
> On Wed, Nov 07, 2001 at 10:43:01PM +0900, GOTO Kentaro wrote:
> >         session.gets("\r\n\r\n")  # read request
> 
> That's right.  The example said ``puts session.gets...'' and since it
> gave an error I deleted the whole line instead of just puts, as I
> should have done.

All input should be read though, I don't know what is going. 
At least, I found that lynx sent request twice.  

And an agent sometimes fails depending on time: 

% ruby -rsocket -e '
    s = TCPSocket.open("localhost", 8082)
    s.print "GET / HTTP/1.0\r\n"
    p s.read'
-e:2:in `read': Connection reset by peer (Errno::ECONNRESET)
        from -e:2

Someone guessed that server would send RST (I can't tcpdump here). 

> Anyway, I am reimplementing it as a single threaded bare-bones daemon,
> taking inspiration from (translation: shamelessly plagiarizing)
> httpd.rb by Michel van de Ven, found on RAA.

For Your Interest: There is WEBrick, which is a web server toolkit.
With WEBrick, DAYTIME server can be written as:

  require "webrick"

  include WEBrick
  GenericServer.new(:Port => 1313, :StartThreads => 1).start{|sock| 
    sock.write(Time.now.to_s + "\n")
  }

The latest tarball:
http://www.notwork.org/ipr/webrick/webrick-20011007.tar.gz
It includes some samples (RFC explorer servlet, HTTPS server etc). 

-- Gotoken