<!--
{
  "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",
    "visionOS: 1.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "NetworkExtension",
  "identifier" : "/documentation/NetworkExtension/NEAppProxyUDPFlow/writeDatagrams(_:sentBy:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network Extension"
    ],
    "preciseIdentifier" : "c:objc(cs)NEAppProxyUDPFlow(im)writeDatagrams:sentByEndpoints:completionHandler:"
  },
  "title" : "writeDatagrams(_:sentBy:completionHandler:)"
}
-->

# writeDatagrams(_:sentBy:completionHandler:)

Write datagrams to the flow.

```
func writeDatagrams(_ datagrams: [Data], sentBy remoteEndpoints: [NWEndpoint], completionHandler: @escaping @Sendable ((any Error)?) -> Void)
```

## Parameters

`datagrams`

An array of <doc://com.apple.documentation/documentation/Foundation/NSData> objects containing datagram payloads to be written.

`remoteEndpoints`

An array of [`NWEndpoint`](/documentation/NetworkExtension/NWEndpoint) objects containing the source endpoints of the datagram payloads in `datagrams`.

`completionHandler`

A block that will be executed by the system on an internal system thread when the data is written into the receive buffer of the socket associated with the flow. If an error occurs while writing the data then a non-nil <doc://com.apple.documentation/documentation/Foundation/NSError> object is passed to the block. See `NEAppProxyFlowError` in [`NEAppProxyFlow`](/documentation/NetworkExtension/NEAppProxyFlow) for a list of possible errors.

---

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)