Type Method
listen(port:backlog:loop:)
Creates a listening server socket bound to any local IPv4 interface on port.
static func listen(port: UInt16, backlog: Int32 = 128, loop: EventLoop = .shared) async throws -> ServerSocket
Parameters
-
port
-
TCP port in host byte order. Passing 0 asks the kernel to assign an ephemeral port.
-
backlog
-
The listen(2) backlog size. Default 128 matches common Linux tuning.
-
loop
-
The event loop to drive. Defaults to shared.
Return Value
A ServerSocket ready to accept connections.
Mentioned In
Discussion
Shorthand for listen(on: SocketAddress.anyIPv4(port:), ...).
Throws
SocketError.socketCreationFailed(_:), SocketError.bindFailed(_:), or SocketError.listenFailed(_:).