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

# nng\_socket(5)

socket handle

## NAME

nng\_socket - socket handle

## SYNOPSIS

```
#include <nng/nng.h>
typedef struct nng_socket_s nng_socket;
```

## DESCRIPTION

An `nng_socket` is a handle to an underlying socket object. All communication between the application and remote Scalability Protocol peers is done through sockets. A given socket can have multiple dialers (`nng_dialer`) and/or listeners (`nng_listener`), and multiple pipes (`nng_pipe`), and may be connected to multiple transports at the same time. However, a given socket will have exactly one protocol associated with it, and is responsible for any state machines or other protocol-specific logic.

**Important**\

The `nng_socket` structure is always passed by value (both for input parameters and return values), and should be treated opaquely. Passing structures this way gives the compiler a chance to perform accurate type checks in functions passing values of this type.

Each `nng_socket` is created by a protocol-specific constructor, such as `nng_rep_open()`. When the socket is no longer needed, it can be closed with `nng_close()`.

### Initialization

A socket may be initialized using the macro `NNG_SOCKET_INITIALIZER` before it is opened, to prevent confusion with valid open sockets.

For example:

```
nng_socket s = NNG_SOCKET_INITIALIZER;
```

## SEE ALSO

[libnng(3)](/libnng/3.md), [nng\_close(3)](/nng_close/3.md), [nng\_getopt(3)](/nng_getopt/3.md), [nng\_setopt(3)](/nng_setopt/3.md), [nng\_socket\_id(3)](/nng_socket_id/3.md), [nng\_dialer(5)](/nng_dialer/5.md), [nng\_listener(5)](/nng_listener/5.md), [nng\_options(5)](/nng_options/5.md), [nng(7)](/nng/7.md)
