---
title: "writeDatagrams(_:sentBy:completionHandler:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/neappproxyudpflow/writedatagrams(_:sentby:completionhandler:)"
---

# writeDatagrams(_:sentBy:completionHandler:)

Write datagrams to the flow.

## Declaration

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

```swift
func writeDatagrams(_ datagrams: [Data], sentBy remoteEndpoints: [NWEndpoint]) async throws
```

## Parameters

- `datagrams`: An array of doc://com.apple.documentation/documentation/Foundation/NSData objects containing datagram payloads to be written.
- `remoteEndpoints`: An array of doc://com.apple.networkextension/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 doc://com.apple.networkextension/documentation/NetworkExtension/NEAppProxyFlow for a list of possible errors.

## See Also

### Handling flow data

- [readDatagrams(completionHandler:)](networkextension/neappproxyudpflow/readdatagrams(completionhandler:)-9z8gw.md)
