<!--
{
  "availability" : [
    "iOS: 9.0.0 - 18.0.0",
    "iPadOS: 9.0.0 - 18.0.0",
    "macCatalyst: 13.1.0 - 18.0.0",
    "macOS: 10.11.0 - 15.0.0",
    "tvOS: 17.0.0 - 18.0.0",
    "visionOS: 1.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "NetworkExtension",
  "identifier" : "/documentation/NetworkExtension/NWTCPConnection",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NWTCPConnection"
  },
  "title" : "NWTCPConnection"
}
-->

# NWTCPConnection

An object to manage a TCP connection, with or without TLS.

```
class NWTCPConnection
```

## Topics

### Monitoring the connection status

[`state`](/documentation/NetworkExtension/NWTCPConnection/state)

The status of the connection.

[`NWTCPConnectionState`](/documentation/NetworkExtension/NWTCPConnectionState)

Defined connection states. New types may be defined in the future.

[`viable`](/documentation/NetworkExtension/NWTCPConnection/isViable)

The viability of a TCP connection indicates whether or not data can be transferred.

[`error`](/documentation/NetworkExtension/NWTCPConnection/error)

The connection-wide error property.

### Transferring data

[`-  readMinimumLength:maximumLength:completionHandler:`](/documentation/NetworkExtension/NWTCPConnection/readMinimumLength(_:maximumLength:completionHandler:))

Read the requested range of bytes.

[`-  readLength:completionHandler:`](/documentation/NetworkExtension/NWTCPConnection/readLength(_:completionHandler:))

Read a certain number of bytes on a connection.

[`-  write:completionHandler:`](/documentation/NetworkExtension/NWTCPConnection/write(_:completionHandler:))

Write the data to the connection.

[`-  writeClose`](/documentation/NetworkExtension/NWTCPConnection/writeClose())

Close the connection for writing.

### Canceling the connection

[`-  cancel`](/documentation/NetworkExtension/NWTCPConnection/cancel())

Cancel the connection.

### Responding to network changes

[`hasBetterPath`](/documentation/NetworkExtension/NWTCPConnection/hasBetterPath)

If a connection has a better path, new connections would use a different interface.

[`-  initWithUpgradeForConnection:`](/documentation/NetworkExtension/NWTCPConnection/init(upgradeFor:))

This convenience initializer can be used to create a new connection that will only be connected if there exists a better path (as determined by the system) to the remote endpoint of the original connection.

### Getting connection properties

[`endpoint`](/documentation/NetworkExtension/NWTCPConnection/endpoint)

The destination endpoint with which this connection was created.

[`localAddress`](/documentation/NetworkExtension/NWTCPConnection/localAddress)

The IP address endpoint from which the connection was established.

[`remoteAddress`](/documentation/NetworkExtension/NWTCPConnection/remoteAddress)

The IP address endpoint to which the connection was established.

[`connectedPath`](/documentation/NetworkExtension/NWTCPConnection/connectedPath)

The network path over which the connection was established.

[`txtRecord`](/documentation/NetworkExtension/NWTCPConnection/txtRecord)

The TXT record associated with a connected Bonjour service endpoint.

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Hashable`](/documentation/Swift/Hashable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)