Skip to content

Instantly share code, notes, and snippets.

@jarib
Created January 29, 2010 04:06
Show Gist options
  • Save jarib/289439 to your computer and use it in GitHub Desktop.
Save jarib/289439 to your computer and use it in GitHub Desktop.
$ cat bug.rb
require "socket"
loop do
s = TCPServer.new("localhost", 5000)
p s => Socket.unpack_sockaddr_in(s.getsockname)
end
$ ruby bug.rb
{#<TCPServer:0x100154950>=>[5000, "::1"]}
{#<TCPServer:0x100154748>=>[5000, "fe80::1%lo0"]}
{#<TCPServer:0x100154590>=>[5000, "127.0.0.1"]}
bug.rb:4:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from bug.rb:4:in `new'
from bug.rb:4
from bug.rb:3:in `loop'
from bug.rb:3
$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment