---
title: "readDatagrams(completionHandler:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/neappproxyudpflow/readdatagrams(completionhandler:)-9z8gw"
---

# readDatagrams(completionHandler:)

Read datagrams from the flow.

## Declaration

```swift
func readDatagrams(completionHandler: @escaping ([Data]?, [NWEndpoint]?, (any Error)?) -> Void)
```

## Parameters

- `completionHandler`: A block that will be executed by the system on an internal system thread when datagrams have been read from the flow. The block takes the datagrams that were read, the destination endpoints of the datagrams, and an doc://com.apple.documentation/documentation/Foundation/NSError. If an error occurred while reading then error will be non-nil. See NEAppProxyFlowError in doc://com.apple.networkextension/documentation/NetworkExtension/NEAppProxyFlow for a list of possible error codes. If the datagrams and remoteEndpoints arrays are non-nil but are empty, then no more datagrams can be subsequently read from the flow. note: The completion handler is only called for the single read operation that was initiated by calling this method. If the caller wants to read more datagrams then it should call this method again to schedule another read operation and another execution of the completion handler block.

## See Also

### Handling flow data

- [writeDatagrams(_:sentBy:completionHandler:)](networkextension/neappproxyudpflow/writedatagrams(_:sentby:completionhandler:).md)
