<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 12.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Network",
  "identifier" : "/documentation/Network/nw_connection_t",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "Network"
    ],
    "preciseIdentifier" : "c:@T@nw_connection_t"
  },
  "title" : "nw_connection_t"
}
-->

# nw_connection_t

A bidirectional data connection between a local endpoint and a remote endpoint.

```
typealias nw_connection_t = any OS_nw_connection
```

## Topics

### Creating Connections

[`nw_connection_create(_:_:)`](/documentation/Network/nw_connection_create(_:_:))

Initializes a new connection to a remote endpoint.

[`nw_connection_set_queue(_:_:)`](/documentation/Network/nw_connection_set_queue(_:_:))

Sets the queue on which all connection events are delivered.

[`nw_connection_start(_:)`](/documentation/Network/nw_connection_start(_:))

Starts establishing a connection.

[`nw_connection_restart(_:)`](/documentation/Network/nw_connection_restart(_:))

Restarts a connection that is in the waiting state.

### Handling State Updates

[`nw_connection_state_t`](/documentation/Network/nw_connection_state_t)

States indicating whether a connection can be used to send and receive data.

[`nw_connection_set_state_changed_handler(_:_:)`](/documentation/Network/nw_connection_set_state_changed_handler(_:_:))

Sets a handler to receive connection state updates.

[`nw_connection_state_changed_handler_t`](/documentation/Network/nw_connection_state_changed_handler_t)

A handler that delivers connection state updates with associated errors.

### Sending and Receiving Data

[`nw_connection_send(_:_:_:_:_:)`](/documentation/Network/nw_connection_send(_:_:_:_:_:))

Sends data on a connection.

[`nw_connection_send_completion_t`](/documentation/Network/nw_connection_send_completion_t)

A completion handler that indicates when the connection has finished processing sent content.

[`nw_content_context_t`](/documentation/Network/nw_content_context_t)

A representation of a message to send or receive, containing protocol metadata and send properties.

[`nw_connection_receive(_:_:_:_:)`](/documentation/Network/nw_connection_receive(_:_:_:_:))

Schedules a single receive completion handler, with a range indicating how many bytes the handler can receive at one time.

[`nw_connection_receive_completion_t`](/documentation/Network/nw_connection_receive_completion_t)

A completion handler that indicates when content has been received by the connection, or that an error was encountered.

[`nw_connection_receive_message(_:_:)`](/documentation/Network/nw_connection_receive_message(_:_:))

Schedules a single receive completion handler for a complete message, as opposed to a range of bytes.

[`nw_connection_batch(_:_:)`](/documentation/Network/nw_connection_batch(_:_:))

Defines a block in which calls to send and receive are processed as a batch to improve performance.

[`nw_connection_get_maximum_datagram_size(_:)`](/documentation/Network/nw_connection_get_maximum_datagram_size(_:))

Accesses the maximum size of a datagram message that can be sent on a connection.

### Canceling Connections

[`nw_connection_cancel(_:)`](/documentation/Network/nw_connection_cancel(_:))

Cancels the connection and gracefully disconnects any established network protocols.

[`nw_connection_force_cancel(_:)`](/documentation/Network/nw_connection_force_cancel(_:))

Cancels the connection and immediately disconnects any established network protocols.

[`nw_connection_cancel_current_endpoint(_:)`](/documentation/Network/nw_connection_cancel_current_endpoint(_:))

Causes the current endpoint to be rejected, allowing the connection to try another resolved address.

### Handling Path Updates

[`nw_connection_copy_current_path(_:)`](/documentation/Network/nw_connection_copy_current_path(_:))

Accesses the network path the connection is using.

[`nw_connection_set_path_changed_handler(_:_:)`](/documentation/Network/nw_connection_set_path_changed_handler(_:_:))

Sets a handler that receives network path updates.

[`nw_connection_path_event_handler_t`](/documentation/Network/nw_connection_path_event_handler_t)

A handler that delivers network path updates.

[`nw_connection_set_viability_changed_handler(_:_:)`](/documentation/Network/nw_connection_set_viability_changed_handler(_:_:))

Sets a handler that receives updates when data can be sent and received.

[`nw_connection_set_better_path_available_handler(_:_:)`](/documentation/Network/nw_connection_set_better_path_available_handler(_:_:))

Sets a handler that receives updates when an alternative network path is preferred over the current path.

[`nw_connection_boolean_event_handler_t`](/documentation/Network/nw_connection_boolean_event_handler_t)

A handler that receives Boolean state updates from a connection, such as viability and better path state.

### Collecting Connection Metrics

[`nw_establishment_report_t`](/documentation/Network/nw_establishment_report_t)

A report that provides metrics about how a connection was established.

[`nw_connection_access_establishment_report(_:_:_:)`](/documentation/Network/nw_connection_access_establishment_report(_:_:_:))

Requests a copy of the connection’s establishment report once the connection is in the ready state.

[`nw_establishment_report_access_block_t`](/documentation/Network/nw_establishment_report_access_block_t)

A block that delivers a connection’s establishment report when it’s in the ready state.

[`nw_data_transfer_report_t`](/documentation/Network/nw_data_transfer_report_t)

A report that provides metrics about data being sent and received on a connection.

[`nw_connection_create_new_data_transfer_report(_:)`](/documentation/Network/nw_connection_create_new_data_transfer_report(_:))

Begins a new data transfer report, which can later be collected.

### Copying Connection State

[`nw_connection_copy_protocol_metadata(_:_:)`](/documentation/Network/nw_connection_copy_protocol_metadata(_:_:))

Retrieves the connection-wide metadata for a specific protocol.

[`nw_connection_copy_endpoint(_:)`](/documentation/Network/nw_connection_copy_endpoint(_:))

Accesses the endpoint with which the connection was created.

[`nw_connection_copy_parameters(_:)`](/documentation/Network/nw_connection_copy_parameters(_:))

Accesses the parameters with which the connection was created.

[`nw_connection_copy_description(_:)`](/documentation/Network/nw_connection_copy_description(_:))

Copies the description of the connection as a string.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)