Instance Method


Create a TCP connection.


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



The remote endpoint to connect to.


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


The TLS protocol parameters to use. If enableTLS is true and this parameter is nil then the default TLS parameters will be used.


An optional delegate object that conforms to the NWTCPConnectionAuthenticationDelegate protocol.

Return Value

A 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.


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.

See Also