Socket errors

Howdy,

The documentation for Socket#accept gives an example of a ruby script
to bind to a socket and listen for incoming connections. Unfortunately
the script fails with the bind method.

Here is the script with the addition of the line to display the
returned value from the Socket.pack_sockaddr_in call.

#!/usr/bin/env ruby

In one script, start this first

require ‘socket’
include Socket::Constants
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( 2200, ‘localhost’ )
p sockaddr
socket.bind( sockaddr )
socket.listen( 5 )
client, client_sockaddr = socket.accept
puts “The client said, ‘#{socket.readline.chomp}’”
client.puts "Hello from script one!"socket.close

Here is the output;

“\034\036\b\230\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000”
./r.rb:9:in `bind’: Invalid argument - bind(2) (Errno::EINVAL)
from ./r.rb:9

bruce:~/tmp$ uname -aDarwin carlpowerbook 8.8.0 Darwin Kernel Version
8.8.0: Fri Sep 8 17:18:57 PDT 2006;
root:xnu-792.12.6.obj~1/RELEASE_PPC Power Macintosh powerpc
bruce:~/tmp$ ruby -vruby 1.8.5 (2006-08-25) [powerpc-darwin8.8.0]

I tried the same code on a Solaris 9 box at work and got a similar
error message.

However this code works with Linux (ubuntu) with the same version of
ruyb (1.8.5)

Has anyone heard of this or similar problems before?

thanks,
Bruce.

thnx bruce…