From: Brian Candler Date: 2003-08-14T07:23:04+09:00 Subject: Re: Ruby listens IPv6 On Thu, Aug 14, 2003 at 07:08:42AM +0900, Scott Thompson wrote: > I ran this code on my machine (as a privileged user so I could listen > to port 80) and happily tried to point my web browser at it to see what > kind of stuff the browser would send to the script. > > Unfortunately, my web browser gave me a "could not connect" error. > Hrmmmm... I think it was probably not "could not connect" exactly, more like "failed to get any response from server", since your program does not send back any response down the TCP socket. Your web browser won't display anything unless the server follows the HTTP protocol. I suggest you test your program using 'telnet'. For example, modify it to use port 8888 instead of port 80 (that way you don't need to be root to run it). Run it in one window, and in another do telnet 127.0.0.1 8888 This will establish a TCP connection; stuff you type in the telnet session is sent down the connection, and anything which is sent back will be displayed. Your program works; Ruby will use an IPv6 socket if it's available, but such a socket is able to accept incoming IPv4 connections too. To make such a TCP server work properly you really want to start off a new thread for each incoming request, so that multiple requests can be handled in parallel. There's an example midway through http://www.rubygarden.org/ruby?SingletonTutorial of a fake POP3 server. But for a real-life webserver, you could just use Webrick - which is bundled with ruby-1.8.0 now anyway. Cheers, Brian.