From: Dave Thomas Date: 2000-12-31T07:58:50+09:00 Subject: [ruby-talk:8378] Re: New to Ruby takaoueda@my-deja.com writes: > For AF_INET, we must give port numbers and IP addresses in place of the > file name. Also, I think we must use something called struct sockaddr, > which corresponds to GNU C's struct sockaddr_in in this case. But > how? You have to construct a sockaddr_in. See Stevens Unix Network Programming for details, but for AF_INET it contains a family, a post, and an IP address. > Would anyone kindly supply correct ones? Here's a trivial server require "socket" s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) n = Socket.gethostbyname("localhost") sa = [Socket::AF_INET, 3456, n[3], 0, 0].pack("snA4NN") s.bind(sa) s.listen(4) loop do a = s.accept p a a[0].close end