Total newbie, but I think I found a bug in Socket?

Discussion in 'Ruby' started by Patrick Toomey, Sep 6, 2006.

  1. Hello,
    Fair warning...I'm extremely new to Ruby so please pardon any
    ignorance on my part.

    Anyway, so the first thing I start to play around with after
    reading through Programming Ruby is the socket library. Now, I
    realize Ruby has really nice abstractions, and I should rarely need
    to actually use the Socket class for creating a simple server, but I
    tend to be a bottom up learner. So, I was attempting to run the
    following code from the ruby-doc website:

    # 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' )
    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

    now, after running this script on both ruby 1.8.4 and 1.8.5 on Mac OS
    X I received an error "`bind': Invalid argument - bind(2)
    (Errno::EINVAL) " I proceed to run the script on linux on 1.8.4
    and 1.8.5 and discover that bind works, but that
    "socket.readline.chomp" should really be "client.readline.chomp".
    Anyway, the point is that the code runs just fine on linux but not OS
    X. A quick investigation finds that the problem is the call
    "Socket.pack_sockaddr_in( 2200, 'localhost' )". On Linux this call
    always returns a string that is 16 characters long. On Mac OS X this
    call returns a string that is 16 characters long so long as I don't
    use 'localhost' for the hostname. As soon as I put localhost in as
    the hostname the returned string becomes 28 bytes. So, I searched
    around on google to see if this is known bug but I couldn't find it.
    Anyone have any words of advice?

    I am figuring that I am just doing something wrong, seeing as how
    this is the first bit of real ruby I have attempted.

    Thanks,
    Patrick
    Patrick Toomey, Sep 6, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian
    Replies:
    0
    Views:
    279
  2. fitwell
    Replies:
    3
    Views:
    503
    fitwell
    Sep 12, 2003
  3. Replies:
    0
    Views:
    583
  4. inhahe
    Replies:
    5
    Views:
    382
    Peter Decker
    Jan 2, 2010
  5. KevinSimonson

    Think I May Have Found a Bug with wc -l

    KevinSimonson, Mar 19, 2011, in forum: Java
    Replies:
    18
    Views:
    500
Loading...

Share This Page