<!--
{
  "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/NWUDPSession",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NWUDPSession"
  },
  "title" : "NWUDPSession"
}
-->

# NWUDPSession

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

```
class NWUDPSession
```

## Overview

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

## Topics

### Monitoring the session state

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

The current state of the UDP session.

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

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

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

### Selecting remote endpoints

[`resolvedEndpoint`](/documentation/NetworkExtension/NWUDPSession/resolvedEndpoint)

The currently targeted remote endpoint.

[`-  tryNextResolvedEndpoint`](/documentation/NetworkExtension/NWUDPSession/tryNextResolvedEndpoint())

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

### Transferring data

[`-  setReadHandler:maxDatagrams:`](/documentation/NetworkExtension/NWUDPSession/setReadHandler(_:maxDatagrams:))

Set a read handler for datagrams.

[`-  writeDatagram:completionHandler:`](/documentation/NetworkExtension/NWUDPSession/writeDatagram(_:completionHandler:))

Write a single datagram.

[`-  writeMultipleDatagrams:completionHandler:`](/documentation/NetworkExtension/NWUDPSession/writeMultipleDatagrams(_:completionHandler:))

Write multiple datagrams.

[`maximumDatagramLength`](/documentation/NetworkExtension/NWUDPSession/maximumDatagramLength)

The maximum size of a datagram to be written currently.

### Canceling the session

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

Cancel the session.

### Responding to network changes

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

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

[`-  initWithUpgradeForSession:`](/documentation/NetworkExtension/NWUDPSession/init(upgradeFor:))

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

### Getting session properties

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

The destination endpoint with which this session was created.

[`currentPath`](/documentation/NetworkExtension/NWUDPSession/currentPath)

The current evaluated path for the session’s [`resolvedEndpoint`](/documentation/NetworkExtension/NWUDPSession/resolvedEndpoint) property.

## Relationships

### Conforms To

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

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

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

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

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

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

### 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)