Ruby Socket: I found a misstake in the doc. Can someone confirm itand who's gonna fix this doc-error

Discussion in 'Ruby' started by kazaam, Oct 5, 2007.

  1. kazaam

    kazaam Guest

    Hi,
    I'm playing around with sockets in ruby and took a look at the docs(http://www.ruby-doc.org/stdlib/libdoc/socket/rdoc/index.html). There are some examples like this here(http://www.ruby-doc.org/stdlib/libdoc/socket/rdoc/classes/Socket.html#M004166):

    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

    But that example is wrong! It has to be client.readline.chomp and not socket.readline.chomp. Take this example by me:

    #!/usr/bin/env ruby

    $Verbose=true

    require 'socket'

    mysocket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
    socketaddress = Socket.pack_sockaddr_in( 2201, 'localhost' )
    mysocket.bind(socketaddress)
    mysocket.listen( 5 )
    client, client_sockaddr = mysocket.accept
    puts client.readline.chomp #reading from the client fd
    mysocket.close

    execute it and connect with netcat: "nc localhost 2201" , now type something in netcat and you will see everything is fine but now let's change it to the doc way:

    #!/usr/bin/env ruby

    $Verbose=true

    require 'socket'

    mysocket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
    socketaddress = Socket.pack_sockaddr_in( 2201, 'localhost' )
    mysocket.bind(socketaddress)
    mysocket.listen( 5 )
    client, client_sockaddr = mysocket.accept
    puts mysocket.readline.chomp #reading from the socket fd
    mysocket.close

    If you connect now to it with nc the ruby-script will crash:
    ../sockettest.rb:13:in `readline': Transport endpoint is not connected (Errno::ENOTCONN)
    from ./sockettest.rb:13


    Can someone confirm it and who's gonna fix this doc-error?
     
    kazaam, Oct 5, 2007
    #1
    1. Advertisements

  2. kazaam

    James Britt Guest

    This might help:

    http://www.ruby-doc.org/documentation-guidelines.html


    --
    James Britt

    "The use of anthropomorphic terminology when dealing with
    computing systems is a symptom of professional immaturity."
    - Edsger W. Dijkstra
     
    James Britt, Oct 5, 2007
    #2
    1. Advertisements

  3. kazaam

    kazaam Guest

    Can noone confirm this?
     
    kazaam, Oct 6, 2007
    #3
  4. It's not even been a full day since your original post. Relax.
     
    Logan Capaldo, Oct 6, 2007
    #4
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.