<!--
{
  "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/NEProvider/createTCPConnection(to:enableTLS:tlsParameters:delegate:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NEProvider(im)createTCPConnectionToEndpoint:enableTLS:TLSParameters:delegate:"
  },
  "title" : "createTCPConnection(to:enableTLS:tlsParameters:delegate:)"
}
-->

# createTCPConnection(to:enableTLS:tlsParameters:delegate:)

Create a TCP connection.

```
func createTCPConnection(to remoteEndpoint: NWEndpoint, enableTLS: Bool, tlsParameters TLSParameters: NWTLSParameters?, delegate: Any?) -> NWTCPConnection
```

## Parameters

`remoteEndpoint`

The remote endpoint to connect to.

`enableTLS`

A flag indicating if the TLS protocol should be used to secure the communication over the connection.

`TLSParameters`

The TLS protocol parameters to use. If `enableTLS` is <doc://com.apple.documentation/documentation/Swift/true> and this parameter is nil then the default TLS parameters will be used.

`delegate`

An optional delegate object that conforms to the [`NWTCPConnectionAuthenticationDelegate`](/documentation/NetworkExtension/NWTCPConnectionAuthenticationDelegate) protocol.

## Return Value

A [`NWTCPConnection`](/documentation/NetworkExtension/NWTCPConnection) object. The underlying connection is in the process of being established. You can observe the connection’s `state` property using KVO to determine when the connection is successfully established or fails due to an error. For information about KVO, see [Key-Value Observing Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#//apple_ref/doc/uid/10000177i).

## Discussion

This method provides a convenient way to create TCP connections from a Network Extension Provider. It is preferred over using the sockets API. For instance, the Tunnel Provider can use this method to create a secure TCP connection with the tunnel server that can be used to tunnel network data.

---

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)