<!--
{
  "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/createUDPSession(to:from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NEProvider(im)createUDPSessionToEndpoint:fromEndpoint:"
  },
  "title" : "createUDPSession(to:from:)"
}
-->

# createUDPSession(to:from:)

Creates a UDP session.

```
func createUDPSession(to remoteEndpoint: NWEndpoint, from localEndpoint: NWHostEndpoint?) -> NWUDPSession
```

## Parameters

`remoteEndpoint`

The remote endpoint to send UDP datagrams to.

`localEndpoint`

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`](/documentation/NetworkExtension/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.

## Discussion

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.

---

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)