ipsocket.peeraddr([reverse_lookup]) => [address_family, port, hostname, numeric_address]
Instance Public methods
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
:hostname
, hostname is obtained from numeric_address using
reverse lookup. Or if it is false
, or :numeric
,
hostname is same as numeric_address. Or if it is nil
or
ommitted, obeys to ipsocket.do_not_reverse_lookup
. See
Socket.getaddrinfo
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"] }
Please login to continue.