<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Event",
  "identifier" : "/documentation/Event/ServerSocket/accept()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Event"
    ],
    "preciseIdentifier" : "s:5Event12ServerSocketC6acceptAA0C0CyYaKF"
  },
  "title" : "accept()"
}
-->

# accept()

Awaits and returns a single incoming TCP connection.

```
func accept() async throws -> Socket
```

## Return Value

A connected [`Socket`](/documentation/Event/Socket) for the newly-accepted client.

## Discussion

Registers a one-shot `EV_READ` event on the listening descriptor, drives the
event loop via [`runOnce()`](/documentation/Event/EventLoop/runOnce()), then calls `accept(2)` in the ready
callback. The returned [`Socket`](/documentation/Event/Socket) owns its descriptor and is configured for
non-blocking I/O; read/write it via the normal [`read(maxBytes:)`](/documentation/Event/Socket/read(maxBytes:)) /
[`write(_:)`](/documentation/Event/Socket/write(_:)) APIs.

> Throws: ``doc://Event/documentation/Event/SocketError/acceptFailed(_:)`` if `accept(2)` returns a negative
> value.

> SeeAlso: ``doc://Event/documentation/Event/ServerSocket/connections`` for a streaming alternative.