Feature #3953

TCPSocket / UDPSocket do not accept IPAddr objects.

Added by Hal Brodigan over 3 years ago. Updated over 1 year ago.

[ruby-core:32824]
Status:Assigned
Priority:Normal
Assignee:Akinori MUSHA
Category:ext
Target version:next minor

Description

=begin
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

=end

History

#1 Updated by Akira Tanaka about 2 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 about 2 years ago

  • Category set to ext
  • Assignee set to Akinori MUSHA

knu, how do you think?

#3 Updated by Shyouhei Urabe about 2 years ago

  • Status changed from Open to Assigned

#4 Updated by Yusuke Endoh over 1 year ago

  • Target version set to next minor

Also available in: Atom PDF