Skip to content

Instantly share code, notes, and snippets.

@mattyoho
Created December 14, 2010 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattyoho/739876 to your computer and use it in GitHub Desktop.
Save mattyoho/739876 to your computer and use it in GitHub Desktop.
Modified snippet from the echo server code example in http://tomayko.com/writings/unicorn-is-unix
# Minor modification on line 8 of the echo server example to
# avoid IPv4/IPv6 discrepancies when resolving 'localhost' on
# some systems, such as Mac OS X 10.6.
acceptor = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
# Passing 'localhost' below breaks when it resolves to an IPv6 address
address = Socket.pack_sockaddr_in(4242, Socket::INADDR_LOOPBACK)
acceptor.bind(address)
acceptor.listen(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment