Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Socket#accept

() -> [ ::Socket, ::Addrinfo ]
socket.accept => [client_socket, client_addrinfo]

Accepts a next connection. Returns a new Socket object and Addrinfo object.

Example
serv = Socket.new(:INET, :STREAM, 0)
serv.listen(5)
c = Socket.new(:INET, :STREAM, 0)
c.connect(serv.connect_address)
p serv.accept #=> [#<Socket:fd 6>, #<Addrinfo: 127.0.0.1:48555 TCP>]