<!--
{
  "availability" : [

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

# listen(on:backlog:loop:)

Creates a listening server socket bound to a specific [`SocketAddress`](/documentation/Event/SocketAddress).

```
static func listen(on address: SocketAddress, backlog: Int32 = 128, loop: EventLoop = .shared) async throws -> ServerSocket
```

## Parameters

`address`

The local endpoint to bind. Only IPv4 is currently supported —
passing an IPv6 address will succeed at bind time only if the caller has
previously coerced the kernel’s `AF_INET` socket to accept it (generally
not recommended; IPv6 server support is a future enhancement).

`backlog`

The `listen(2)` backlog size.

`loop`

The event loop to drive.

## Return Value

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

## Discussion

Applies `SO_REUSEADDR` before `bind(2)` so that restart-after-crash doesn’t
block on `TIME_WAIT` sockets. On failure, closes the allocated fd before
throwing, so no descriptor leaks (constitution Principle II).

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