On 03.06.2010 04:31, Joel VanderWerf wrote:
> Caleb Clausen wrote:
>> On 6/2/10, Ted Pon<> wrote:
>>> Hi all,
>>>
>>> I am a student learning ruby and I am getting an error that I can't
>>> figure out. It works on my teacher's mac, however does not on my laptop.
>>>
>>> Windows Vista 64-bit
>>> My ruby version is: 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]
>>>
>>>
>>> Here is what I've tried in cmd
>>>
>>> irb
>>>
>>> irb(main):002:0> require 'socket'
>>> => true
>>> irb(main):005:0> TCPSocket.open('0.0.0.0', 888
>>> Errno::EADDRNOTAVAIL: The requested address is not valid in its context.
>>> - conne
>>> ct(2)
>>> from (irb):5:in `initialize'
>>> from (irb):5:in `open'
>>> from (irb):5
>>> from C:/Ruby19/bin/irb:12:in `<main>'
>>>
>>> Any help would be appreciated!
>>
>> Apparently, 0.0.0.0 is treated as a loopback address on the mac. Apple
>> got this wrong; that's a broadcast address and should be treated as
>> the same as 255.255.255.255. 127.0.0.1 is the canonical loopback
>> address, and that's what you should use for greatest portability.
>
> IIUC 0.0.0.0 is the default route, not a broadcast addr. If you bind a
> tcp server to 0.0.0.0, then you can accept connections from any
> interface. I didn't know you could use this on the client side, too.
But you just said that it's the default route, which is something used
by a client. I don't have my Stevenson handy but IIRC the situation is
like this:
1. 0.0.0.0 when used to bind a server socket is a wildcard for "all
interfaces", which means whichever IP is used to address this host the
socket will listen. In contrast if you bind to 127.0.0.1 you can only
connect from the local machine.
irb(main):001:0> srv = TCPServer.new '0.0.0.0', 33445
=> #<TCPServer:0x104f6400>
irb(main):002:0> srv.close
=> nil
irb(main):003:0> srv = TCPServer.open '0.0.0.0', 33445
=> #<TCPServer:0x106d00c8>
irb(main):004:0> srv.close
=> nil
2. 0.0.0.0 cannot be used as a valid address to connect to - you get
EADDRNOTAVAIL as shown above. Broadcast addresses have all bits of the
host part set and consequently typically end in .255:
http://en.wikipedia.org/wiki/Broadcast_address
http://en.wikipedia.org/wiki/Ip_address
I'd say, if this is possible on a Mac then Apple (or BSD) is doing
something weird here and probably not according to the specs.
3. In routing tables it denotes the default route and is used with
netmask 0:
http://en.wikipedia.org/wiki/0.0.0.0
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/