From: Massimiliano Mirra <list / chromatic-harp.com>
Subject: [ruby-talk:24481] TCPServer example in PP book
Date: Wed, 7 Nov 2001 13:16:08 +0900

> require 'socket'
> 
> class TimeServer < TCPServer
>   def run
>     while ( session = accept )
>       session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"

        session.gets("\r\n\r\n")  # read request

>       session.print "<html><body><h1>#{Time.now}</h1></body></html>\r\n"
>       session.close
>     end
>   end
> end
> 
> if $0 == __FILE__
>   timeserv = TimeServer.new('localhost', '8082')
>   timeserv.run
> end
>
> When I connect with e.g. lynx localhost:8082, lynx first results in
> "Alert!: Unexpected server disconnect." and then shows expected page
> with time and date.  The example on the book, of course, works
> perfectly and shows in the expected page immediately.  Could anyone
> point out what am I doing wrong, please?

The socket seems to be blocked by unflushed request.  

I have no idea about platform dependencies.  Anyone?

-- Gotoken