Forum: Ruby Socket errors

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bruce W. (Guest)
on 2007-01-17 09:47
(Received via mailing list)

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 = 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;

./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?

Anjum P. (Guest)
on 2007-01-17 12:39
(Received via mailing list)
thnx bruce..
This topic is locked and can not be replied to.