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 the same as numeric_address. Or if it is nil
or omitted, 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"] }
Lookups the IP address of host.
require 'socket' IPSocket.getaddress("localhost") #=> "127.0.0.1" IPSocket.getaddress("ip6-localhost") #=> "::1"
returns a list of addrinfo objects as an array.
This method converts nodename (hostname) and service (port) to addrinfo. Since the conversion is not unique, the result is a list of addrinfo objects.
nodename or service can be nil if no conversion intended.
family, socktype and protocol are hint for preferred protocol. If the result will be used for a socket with SOCK_STREAM, SOCK_STREAM should be specified as socktype. If so, Addrinfo.getaddrinfo
returns addrinfo list appropriate for SOCK_STREAM. If they are omitted or nil is given, the result is not restricted.
Similarly, PF_INET6 as family restricts for IPv6.
flags should be bitwise OR of Socket::AI_??? constants such as follows. Note that the exact list of the constants depends on OS.
AI_PASSIVE Get address to use with bind() AI_CANONNAME Fill in the canonical name AI_NUMERICHOST Prevent host name resolution AI_NUMERICSERV Prevent service name resolution AI_V4MAPPED Accept IPv4-mapped IPv6 addresses AI_ALL Allow all addresses AI_ADDRCONFIG Accept only if any address is assigned
Note that socktype should be specified whenever application knows the usage of the address. Some platform causes an error when socktype is omitted and servname is specified as an integer because some port numbers, 512 for example, are ambiguous without socktype.
Addrinfo.getaddrinfo("www.kame.net", 80, nil, :STREAM) #=> [#<Addrinfo: 203.178.141.194:80 TCP (www.kame.net)>, # #<Addrinfo: [2001:200:dff:fff1:216:3eff:feb1:44d7]:80 TCP (www.kame.net)>]
returns nodename and service as a pair of strings. This converts struct sockaddr in addrinfo to textual representation.
flags should be bitwise OR of Socket::NI_??? constants.
Addrinfo.tcp("127.0.0.1", 80).getnameinfo #=> ["localhost", "www"] Addrinfo.tcp("127.0.0.1", 80).getnameinfo(Socket::NI_NUMERICSERV) #=> ["localhost", "80"]
Closes the SOCKS connection.
Use Addrinfo.getaddrinfo
instead. This method is deprecated for the following reasons:
The 3rd element of the result is the address family of the first address. The address families of the rest of the addresses are not returned.
gethostbyname() may take a long time and it may block other threads. (GVL cannot be released since gethostbyname() is not thread safe.)
This method uses gethostbyname() function already removed from POSIX.
This method lookups host information by hostname.
TCPSocket.gethostbyname("localhost") #=> ["localhost", ["hal"], 2, "127.0.0.1"]
Returns the remote address as an array which contains address_family and unix_path.
Example
serv = UNIXServer.new("/tmp/sock") c = UNIXSocket.new("/tmp/sock") p c.peeraddr #=> ["AF_UNIX", "/tmp/sock"]
Closes self
for both reading and writing.
Raises IOError
if reading or writing is attempted.
Related: StringIO#close_read
, StringIO#close_write
.
Returns true
if self
is closed for both reading and writing, false
otherwise.
Reads and returns the next character from the stream; see Character IO.
Pushes back (“unshifts”) a character or integer onto the stream; see Character IO.
Pushes back (“unshifts”) an 8-bit byte onto the stream; see Byte IO.
Reads and returns the next 8-bit byte from the stream; see Byte IO.
Reads and returns a line from the stream; assigns the return value to $_
; see Line IO.
Sets current codepage. The WIN32OLE.codepage
is initialized according to Encoding.default_internal
. If Encoding.default_internal
is nil then WIN32OLE.codepage
is initialized according to Encoding.default_external
.
WIN32OLE.codepage = WIN32OLE::CP_UTF8 WIN32OLE.codepage = 65001
Returns current locale id (lcid). The default locale is WIN32OLE::LOCALE_SYSTEM_DEFAULT
.
lcid = WIN32OLE.locale
Sets current locale id (lcid).
WIN32OLE.locale = 1033 # set locale English(U.S) obj = WIN32OLE::Variant.new("$100,000", WIN32OLE::VARIANT::VT_CY)
Runs the early binding method to set property. The 1st argument specifies dispatch ID, the 2nd argument specifies the array of arguments, the 3rd argument specifies the array of the type of arguments.
excel = WIN32OLE.new('Excel.Application') excel._setproperty(558, [true], [WIN32OLE::VARIANT::VT_BOOL]) # same effect as excel.visible = true
Sets property of OLE object. When you want to set property with argument, you can use this method.
excel = WIN32OLE.new('Excel.Application') excel.Visible = true book = excel.workbooks.add sheet = book.worksheets(1) sheet.setproperty('Cells', 1, 2, 10) # => The B1 cell value is 10.
Returns a new Hash
object whose entries are those for which the block returns a truthy value:
h = {foo: 0, bar: 1, baz: 2} h.select {|key, value| value < 2 } # => {:foo=>0, :bar=>1}
Returns a new Enumerator
if no block given:
h = {foo: 0, bar: 1, baz: 2} e = h.select # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:select> e.each {|key, value| value < 2 } # => {:foo=>0, :bar=>1}