Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Socket.new

(::Symbol | ::Integer domain, ::Symbol | ::Integer socktype, ?::Integer protocol) -> ::Socket
Socket.new(domain, socktype [, protocol]) => socket

Creates a new socket object.

domain should be a communications domain such as: :INET, :INET6, :UNIX, etc.

socktype should be a socket type such as: :STREAM, :DGRAM, :RAW, etc.

protocol is optional and should be a protocol defined in the domain. If protocol is not given, 0 is used internally.

Example
Socket.new(:INET, :STREAM) # TCP socket
Socket.new(:INET, :DGRAM)  # UDP socket
Socket.new(:UNIX, :STREAM) # UNIX stream socket
Socket.new(:UNIX, :DGRAM)  # UNIX datagram socket