Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Total newbie, but I think I found a bug in Socket?

Reply
Thread Tools

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

 
 
Patrick Toomey
Guest
Posts: n/a
 
      09-06-2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Think I May Have Found a Bug with wc -l KevinSimonson Java 18 03-21-2011 11:49 AM
I think I found a bug in Python 2.6.4 (in the inspect module) inhahe Python 5 01-02-2010 09:04 PM
BT Total Broadband vs BT Business Total John Y UK VOIP 2 02-02-2007 09:27 AM
Namespace not found in aspx but IS found in code behind William Parker ASP .Net 1 06-27-2004 06:13 AM
found a bug i think, can anyone confirm Ian ASP .Net 0 05-04-2004 03:39 PM



Advertisments