Please forgive me if this sounds a bit juvenile. I’m not as well
versed in network programming as I might like to be. Nevertheless,
here goes.
I’m looking at the book “Teach Yourself Ruby in 21 days” from Sams
publishing. I was reading “day 19” in which the Mr. Slagell presents a
page of code that implements a very simplistic web server. Since I’ve
done a little socket programming, I was curious to see what would
happen if I played with the code. I entered the following program :
···
#----------
require ‘socket’
def main
listener = TCPServer.new(“localhost”, (ARGV[0] || 80).to_i)
loop do
puts "listening"
session = listener.accept
session.each do | line |
puts line
end
session.close
end
end
main
#----------
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…
After trying the “server” on several ports with no success, checking my
firewall settings etc… and generally poking around I finally had the
wherewithall to run the program and use the “netstat” command to see if
the port was actually being listened to.
I found the line… it looks like this:
tcp6 0 0 localhost.http .
LISTEN
The interesting part is that this is the ONLY port on my whole system
that is marked as using IPv6. Hmmm…
What I know about IPv6 could probably fill a couple of sentences. They
go something like this, “IPv6 is the proposed standard for future
Internet communications. Among a host of features interesting to
networking type, one of the things it does is expands the pool of
available addresses that are available to computers in the world”.
My question is, can someone tell me why my Ruby script is listening on
IPv6? Is it because of the way that Ruby was compiled (I built 1.8 from
sources and am using that)? Or, do I have to do something in
particular to tell the Ruby socket that I want it to use IPv4?
I would also welcome pointers to documentation for neophytes about Ruby
sockets… though you may want to send them to me off-line so the other
folks on the list don’t have to endure them again.
Scott