Name
Socket — General socket class
Synopsis
The Socket
class is
necessary to gain access to all the operating system’s socket
interfaces. Interface structures can be created using
String#pack
.
Required Library
require ’socket’
Inherited Class
BasicSocket
Class Methods
Socket::for_fd(
fd
)
Creates a socket object corresponding to the file descriptor
fd
(an integer).Socket::getaddrinfo(
host
,
port
[,
family
[,
type
[,
proto
[,
flags
]]]])
Returns an array containing socket address information (address family, port number, hostname, host IP address, protocol family, socket type, and protocol).
Socket::getaddrinfo("www.ruby-lang.org", "echo", Socket::AF_INET, Socket::SOCK_DGRAM) # => [["AF_INET", 7, "www", "210.251.121.214", 2, 2, 17]]
Socket::gethostbyaddr(
addr
[,
type
=Socket::AF_INET)
Returns an array containing socket address information (address family, port number, hostname, host IP address, protocol family, socket type, and protocol).
Socket::getaddrinfo("www.ruby-lang.org", "echo", Socket::AF_INET, Socket::SOCK_DGRAM) # => [["AF_INET", 7, "www", "210.251.121.214", 2, 2, 17]]
Socket::gethostbyname(
name
)
Returns an array containing host information retrieved from a host
name
.Socket.gethostbyaddr(([127,0,0,1].pack("CCCC"))) # => ["ev", ["localhost", "ev.netlab.jp"], 2, "\177\000\000\001"]
Socket::gethostname
Returns the current hostname.
Socket::getnameinfo(
addr
[,
flags
])
Returns an array containing the name of the host and service retrieved from the specified socket address information.
addr
may be ...
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.