An object to manage a UDP session to a network endpoint.


class NWUDPSession : NSObject


Since UDP does not include a handshake with the remote endpoint as part of its protocol, it is up to the client of the UDP session to provide feedback on the viability of the current endpoint. If a session is opened to a hostname, the system will resolve that hostname into potentially several IP addresses. Once the session state is NWUDPSessionStateReady, the client should try to write and read datagrams. If there is no response from the remote endpoint, the client can try the next address that was resolved using tryNextResolvedEndpoint.


Monitoring the Session State

var state: NWUDPSessionState

The current state of the UDP session

var isViable: Bool

The viability of a UDP session represents whether or not data can be transferred

Selecting Remote Endpoints

var resolvedEndpoint: NWEndpoint?

The currently targeted remote endpoint.

func tryNextResolvedEndpoint()

Mark the current value of resolvedEndpoint as unusable, and try to switch to the next available endpoint

Canceling the Session

func cancel()

Cancel the session

Responding to Network Changes

var hasBetterPath: Bool

If a session has a better path, new session would use a different interface

init(upgradeFor: NWUDPSession)

This convenience initializer can be used to create a new session based on the original session’s endpoint and parameters.

Getting Session Properties

var endpoint: NWEndpoint

The destination endpoint with which this session was created

var currentPath: NWPath?

The current evaluated path for the session’s resolvedEndpoint property.


Inherits From

Conforms To