Ruby networking

From wikinotes

Sockets

TCP

Socket Files

require "socket"

sock = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0)
sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1)
sock.bind(Socket.pack_sockaddr_un("/var/tmp/foo.sock"))
loop do
  command = sock.recvfrom(1024)  # read entire message with 1024b buffer
end