| # <!-- rdoc-file=ext/socket/ipsocket.c --> | |
| # IPSocket is the super class of TCPSocket and UDPSocket. | |
| # | |
| class IPSocket < BasicSocket | |
| # <!-- | |
| # rdoc-file=ext/socket/ipsocket.c | |
| # - IPSocket.getaddress(host) => ipaddress | |
| # --> | |
| # Lookups the IP address of *host*. | |
| # | |
| # require 'socket' | |
| # | |
| # IPSocket.getaddress("localhost") #=> "127.0.0.1" | |
| # IPSocket.getaddress("ip6-localhost") #=> "::1" | |
| # | |
| def self.getaddress: (String host) -> String | |
| # <!-- | |
| # rdoc-file=ext/socket/ipsocket.c | |
| # - ipsocket.addr([reverse_lookup]) => [address_family, port, hostname, numeric_address] | |
| # --> | |
| # Returns the local address as an array which contains address_family, port, | |
| # hostname and numeric_address. | |
| # | |
| # If `reverse_lookup` is `true` or <code>:hostname</code>, hostname is obtained | |
| # from numeric_address using reverse lookup. Or if it is `false`, or | |
| # <code>:numeric</code>, hostname is the same as numeric_address. Or if it is | |
| # `nil` or omitted, obeys to <code>ipsocket.do_not_reverse_lookup</code>. See | |
| # <code>Socket.getaddrinfo</code> also. | |
| # | |
| # TCPSocket.open("www.ruby-lang.org", 80) {|sock| | |
| # p sock.addr #=> ["AF_INET", 49429, "hal", "192.168.0.128"] | |
| # p sock.addr(true) #=> ["AF_INET", 49429, "hal", "192.168.0.128"] | |
| # p sock.addr(false) #=> ["AF_INET", 49429, "192.168.0.128", "192.168.0.128"] | |
| # p sock.addr(:hostname) #=> ["AF_INET", 49429, "hal", "192.168.0.128"] | |
| # p sock.addr(:numeric) #=> ["AF_INET", 49429, "192.168.0.128", "192.168.0.128"] | |
| # } | |
| # | |
| def addr: (?boolish | :hostname | :numeric reverse_lookup) -> [ String, Integer, String, String ] | |
| # <!-- | |
| # rdoc-file=ext/socket/ipsocket.c | |
| # - ipsocket.inspect -> string | |
| # --> | |
| # Return a string describing this IPSocket object. | |
| # | |
| def inspect: () -> String | |
| # <!-- | |
| # rdoc-file=ext/socket/ipsocket.c | |
| # - ipsocket.peeraddr([reverse_lookup]) => [address_family, port, hostname, numeric_address] | |
| # --> | |
| # Returns the remote address as an array which contains address_family, port, | |
| # hostname and numeric_address. It is defined for connection oriented socket | |
| # such as TCPSocket. | |
| # | |
| # If `reverse_lookup` is `true` or <code>:hostname</code>, hostname is obtained | |
| # from numeric_address using reverse lookup. Or if it is `false`, or | |
| # <code>:numeric</code>, hostname is the same as numeric_address. Or if it is | |
| # `nil` or omitted, obeys to <code>ipsocket.do_not_reverse_lookup</code>. See | |
| # <code>Socket.getaddrinfo</code> also. | |
| # | |
| # TCPSocket.open("www.ruby-lang.org", 80) {|sock| | |
| # p sock.peeraddr #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"] | |
| # p sock.peeraddr(true) #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"] | |
| # p sock.peeraddr(false) #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"] | |
| # p sock.peeraddr(:hostname) #=> ["AF_INET", 80, "carbon.ruby-lang.org", "221.186.184.68"] | |
| # p sock.peeraddr(:numeric) #=> ["AF_INET", 80, "221.186.184.68", "221.186.184.68"] | |
| # } | |
| # | |
| def peeraddr: (?boolish | :hostname | :numeric reverse_lookup) -> [ String, Integer, String, String ] | |
| # <!-- | |
| # rdoc-file=ext/socket/ipsocket.c | |
| # - ipsocket.recvfrom(maxlen) => [mesg, ipaddr] | |
| # - ipsocket.recvfrom(maxlen, flags) => [mesg, ipaddr] | |
| # --> | |
| # Receives a message and return the message as a string and an address which the | |
| # message come from. | |
| # | |
| # *maxlen* is the maximum number of bytes to receive. | |
| # | |
| # *flags* should be a bitwise OR of Socket::MSG_* constants. | |
| # | |
| # ipaddr is the same as IPSocket#{peeraddr,addr}. | |
| # | |
| # u1 = UDPSocket.new | |
| # u1.bind("127.0.0.1", 4913) | |
| # u2 = UDPSocket.new | |
| # u2.send "uuuu", 0, "127.0.0.1", 4913 | |
| # p u1.recvfrom(10) #=> ["uuuu", ["AF_INET", 33230, "localhost", "127.0.0.1"]] | |
| # | |
| def recvfrom: (Integer maxlen, ?Integer flags) -> [ String, [ String, Integer, String, String ] ] | |
| end |