Feature #3953

TCPSocket / UDPSocket do not accept IPAddr objects.

Added by Hal Brodigan about 5 years ago. Updated about 3 years ago.

Assignee:Akinori MUSHA


I noticed that TCPSocket/UDPSocket only accept String IPs/Hostnames, but not IPAddr objects. This is counter-intuitive since IP Addresses, along with Hostnames, are used to connect/bind to sockets.

 require 'socket'
 require 'resolv'

 ip = IPAddr.new(Resolv.getaddress('www.example.com'))
 sock = TCPSocket.new(ip,80)
 TypeError: can't convert IPAddr into String
from (irb):5:in `initialize'
from (irb):5:in `new'
from (irb):5



#1 Updated by Akira Tanaka over 3 years ago

  • Description updated (diff)

If we implement this feature, we need a method for duck type, such as IPAddr#to_ipaddress to convert to IP-address string.

#2 Updated by Hiroshi Nakamura over 3 years ago

  • Category set to ext
  • Assignee set to Akinori MUSHA

knu, how do you think?

#3 Updated by Shyouhei Urabe over 3 years ago

  • Status changed from Open to Assigned

#4 Updated by Yusuke Endoh about 3 years ago

  • Target version set to next minor

Also available in: Atom PDF