Class Socket provides access to the underlying operating system socket implementations. It can be used to provide more operating system specific functionality than the protocol-specific socket classes.
The constants defined under Socket::Constants are also defined under Socket. For example, Socket::AF_INET is usable as well as Socket::Constants::AF_INET. See Socket::Constants for the list of constants.
Ruby’s implementation of Socket causes an exception to be raised based on the error generated by the system dependent implementation. This is why the methods are documented in a way that isolate Unix-based system exceptions from Windows based exceptions. If more information on particular exception is needed please refer to the Unix manual pages or the Windows WinSock reference.
Although the general way to create socket is Socket.new, there are several methods for socket creation for most cases.
TCP client socket: Socket.tcp, TCPSocket.open
TCP server socket: Socket.tcp_server_loop, TCPServer.open
UNIX client socket: Socket.unix, UNIXSocket.open
UNIX server socket: Socket.unix_server_loop, UNIXServer.open
Programming Ruby from The Pragmatic Bookshelf.
Much material in this documentation is taken with permission from Programming Ruby from The Pragmatic Bookshelf.
AF_INET6 = Object.new
lib/ipaddr.rb ext/socket/socket.c ext/socket/lib/socket.rb