Networking Basics
Socket Address
A socket address combines a host and a port into an endpoint.
Socket Address
socket_address.rb
require "socket"
port =
endpoint = Addrinfo.tcp("127.0.0.1", port)
family = endpoint.afamily == Socket::AF_INET ? "ipv4" : "other"
address = endpoint.ip_address
display = "#{address}:#{endpoint.ip_port}"
puts "port=#{port}"
puts "family=#{family}"
puts "address=#{address}"
puts "display=#{display}"
require "socket"
port =
endpoint = Addrinfo.tcp("127.0.0.1", port)
family = endpoint.afamily == Socket::AF_INET ? "ipv4" : "other"
address = endpoint.ip_address
display = "#{address}:#{endpoint.ip_port}"
puts "port=#{port}"
puts "family=#{family}"
puts "address=#{address}"
puts "display=#{display}"
require "socket"
port =
endpoint = Addrinfo.tcp("127.0.0.1", port)
family = endpoint.afamily == Socket::AF_INET ? "ipv4" : "other"
address = endpoint.ip_address
display = "#{address}:#{endpoint.ip_port}"
puts "port=#{port}"
puts "family=#{family}"
puts "address=#{address}"
puts "display=#{display}"
socket address
`Addrinfo.tcp` describes an endpoint locally; it does not connect by itself.