connect

addrinfo.connect([opts]) {|socket| ... }addrinfo.connect([opts]) Instance Public methods creates a socket connected to the address of self. The optional argument opts is options represented by a hash. opts may have following options: :timeout specify the timeout in seconds. If a block is given, it is called with the socket and the value of the block is returned. The socket is returned otherwise. Addrinfo.tcp("www.ruby-lang.org", 80).connect {|s| s.print "GET / HTTP/1.0\r\nH

connect_from

addrinfo.connect_from([local_addr_args], [opts]) {|socket| ... }addrinfo.connect_from([local_addr_args], [opts]) Instance Public methods creates a socket connected to the address of self. If one or more arguments given as local_addr_args, it is used as the local address of the socket. local_addr_args is given for #family_addrinfo to obtain actual address. If local_addr_args is not given, the local address of the socket is not bound. The optional last argument opts is options repre

connect_to

addrinfo.connect_to([remote_addr_args], [opts]) {|socket| ... }addrinfo.connect_to([remote_addr_args], [opts]) Instance Public methods creates a socket connected to remote_addr_args and bound to self. The optional last argument opts is options represented by a hash. opts may have following options: :timeout specify the timeout in seconds. If a block is given, it is called with the socket and the value of the block is returned. The socket is returned otherwise. Addrinfo.tcp("0

family_addrinfo

family_addrinfo(*args) Instance Public methods creates an Addrinfo object from the arguments. The arguments are interpreted as similar to self. Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("www.ruby-lang.org", 80) #=> #<Addrinfo: 221.186.184.68:80 TCP (www.ruby-lang.org:80)> Addrinfo.unix("/tmp/sock").family_addrinfo("/tmp/sock2") #=> #<Addrinfo: /tmp/sock2 SOCK_STREAM>

getnameinfo

addrinfo.getnameinfo => [nodename, service]addrinfo.getnameinfo(flags) => [nodename, service] Instance Public methods returns nodename and service as a pair of strings. This converts struct sockaddr in addrinfo to textual representation. flags should be bitwise OR of Socket::NI_??? constants. Addrinfo.tcp("127.0.0.1", 80).getnameinfo #=> ["localhost", "www"] Addrinfo.tcp("127.0.0.1", 80).getnameinfo(Socket::NI_NUMERICSERV) #=> ["localhost", "80"]

inspect

addrinfo.inspect => string Instance Public methods returns a string which shows addrinfo in human-readable form. Addrinfo.tcp("localhost", 80).inspect #=> "#<Addrinfo: 127.0.0.1:80 TCP (localhost)>" Addrinfo.unix("/tmp/sock").inspect #=> "#<Addrinfo: /tmp/sock SOCK_STREAM>"

inspect_sockaddr

addrinfo.inspect_sockaddr => string Instance Public methods returns a string which shows the sockaddr in addrinfo with human-readable form. Addrinfo.tcp("localhost", 80).inspect_sockaddr #=> "127.0.0.1:80" Addrinfo.tcp("ip6-localhost", 80).inspect_sockaddr #=> "[::1]:80" Addrinfo.unix("/tmp/sock").inspect_sockaddr #=> "/tmp/sock"

ip?

addrinfo.ip? => true or false Instance Public methods returns true if addrinfo is internet (IPv4/IPv6) address. returns false otherwise. Addrinfo.tcp("127.0.0.1", 80).ip? #=> true Addrinfo.tcp("::1", 80).ip? #=> true Addrinfo.unix("/tmp/sock").ip? #=> false

ip_address

addrinfo.ip_address => string Instance Public methods Returns the IP address as a string. Addrinfo.tcp("127.0.0.1", 80).ip_address #=> "127.0.0.1" Addrinfo.tcp("::1", 80).ip_address #=> "::1"

ip_port

addrinfo.ip_port => port Instance Public methods Returns the port number as an integer. Addrinfo.tcp("127.0.0.1", 80).ip_port #=> 80 Addrinfo.tcp("::1", 80).ip_port #=> 80