---
name: "nng_ctx_recv"
section: "3"
platform: "linux"
package: "libnng-dev"
version: "1.10.1-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/nng_ctx_recv"
---

# nng\_ctx\_recv(3)

receive message using context asynchronously

## NAME

nng\_ctx\_recv - receive message using context asynchronously

## SYNOPSIS

```
#include <nng/nng.h>
void nng_ctx_recv(nng_ctx ctx, nng_aio *aio);
```

## DESCRIPTION

The `nng_ctx_recv()` receives a message using the context *s* asynchronously.

When a message is successfully received by the context, it is stored in the *aio* by an internal call equivalent to `nng_aio_set_msg()`, then the completion callback on the *aio* is executed. In this case, `nng_aio_result()` will return zero. The callback function is responsible for retrieving the message and disposing of it appropriately.

**Important**\

Failing to accept and dispose of messages in this case can lead to memory leaks.

If for some reason the asynchronous receive cannot be completed successfully (including by being canceled or timing out), then the callback will still be executed, but `nng_aio_result()` will be non-zero.

**Note**\

The semantics of what receiving a message means varies from protocol to protocol, so examination of the protocol documentation is encouraged.

## RETURN VALUES

None.  (The operation completes asynchronously.)

## ERRORS

`NNG_ECANCELED`

The operation was aborted.

`NNG_ECLOSED`

The context *ctx* is not open.

`NNG_ENOMEM`

Insufficient memory is available.

`NNG_ENOTSUP`

The protocol for context *ctx* does not support receiving.

`NNG_ESTATE`

The context *ctx* cannot receive data in this state.

`NNG_ETIMEDOUT`

The receive timeout expired.

## SEE ALSO

[nng\_aio\_get\_msg(3)](/nng_aio_get_msg/3.md), [nng\_aio\_set\_msg(3)](/nng_aio_set_msg/3.md), [nng\_msg\_alloc(3)](/nng_msg_alloc/3.md), [nng\_strerror(3)](/nng_strerror/3.md), [nng\_aio(5)](/nng_aio/5.md), [nng\_ctx(5)](/nng_ctx/5.md), [nng\_msg(5)](/nng_msg/5.md), [nng(7)](/nng/7.md)
