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

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 wrote:

… and who’s gonna fix this doc-error?

This might help:

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


James B.

“The use of anthropomorphic terminology when dealing with
computing systems is a symptom of professional immaturity.”

  • Edsger W. Dijkstra

Can noone confirm this?

On 10/6/07, kazaam [email protected] wrote:

Can noone confirm this?


kazaam [email protected]

It’s not even been a full day since your original post. Relax.

Hi,

In message “Re: Ruby Socket: I found a misstake in the doc. Can someone
confirm it and who’s gonna fix this doc-error?”
on Sat, 6 Oct 2007 02:25:05 +0900, kazaam [email protected] writes:

|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:

It’s already updated in the source. I guess ruby-doc.org needs update
as well.

          matz.