Instance Method


Create a UDP session.


- (NWUDPSession *)createUDPSessionToEndpoint:(NWEndpoint *)remoteEndpoint fromEndpoint:(NWHostEndpoint *)localEndpoint;



The remote endpoint to send UDP datagrams to.


The local endpoint to bind the UDP session to. If nil, the UDP session will be bound to an ephemeral port on the primary physical interface.

Return Value

A NWUDPSession object. The remote endpoint is in the process of being resolved. You can observe the session’s state property using KVO to determine when the session can be used to send and receive UDP datagrams.


This method provides a convenient way to create UDP 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 UDP connection with the tunnel server that can be used to tunnel network data.

See Also

Creating Network Connections