<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Event",
  "identifier" : "/documentation/Event/Socket/listen(port:backlog:loop:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Event"
    ],
    "preciseIdentifier" : "s:5Event6SocketC6listen4port7backlog4loopAA06ServerB0Cs6UInt16V_s5Int32VAA0A4LoopCtYaKFZ"
  },
  "title" : "listen(port:backlog:loop:)"
}
-->

# 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`](/documentation/Event/EventLoop/shared).

## Return Value

A [`ServerSocket`](/documentation/Event/ServerSocket) ready to accept connections.

## Discussion

Shorthand for `listen(on: SocketAddress.anyIPv4(port:), ...)`.

> Throws: ``doc://Event/documentation/Event/SocketError/socketCreationFailed(_:)``,
> ``doc://Event/documentation/Event/SocketError/bindFailed(_:)``, or ``doc://Event/documentation/Event/SocketError/listenFailed(_:)``.