# NetSocketBinding

`import { NetSocketBinding } from "destack:net/binding";`

Socket binding family.

```ds title="NetSocketBinding"
export interface NetSocketBinding {
    open(options: SocketOpenOptions): Result<SocketHandle, HostError>;
    pair(options: SocketOpenOptions): Result<SocketPair, HostError>;
    bind(socket: SocketHandle, address: &'a readonly SocketAddress): Result<void, HostError>;
    listen(socket: SocketHandle, backlog: uint32): Result<void, HostError>;
    accept(socket: SocketHandle, flags: SocketAcceptFlags): Result<SocketAcceptResult, HostError>;
    connect(socket: SocketHandle, address: &'a readonly SocketAddress): Result<void, HostError>;
    close(socket: SocketHandle): Result<void, HostError>;
    shutdown(socket: SocketHandle, how: SocketShutdown): Result<void, HostError>;
    setNonblocking(socket: SocketHandle, isEnabled: boolean): Result<void, HostError>;
    localAddress(socket: SocketHandle): Result<SocketAddress, HostError>;
    peerAddress(socket: SocketHandle): Result<SocketAddress, HostError>;
    receive(socket: SocketHandle, buffer: &'a [uint8], flags: SocketMessageFlags): Result<uint64, HostError>;
    send(socket: SocketHandle, buffer: &'a readonly [uint8], flags: SocketMessageFlags): Result<uint64, HostError>;
    receiveFrom(socket: SocketHandle, buffer: &'a [uint8], flags: SocketMessageFlags): Result<SocketReceiveFromResult, HostError>;
    sendTo(socket: SocketHandle, buffer: &'a readonly [uint8], address: &'b readonly SocketAddress, flags: SocketMessageFlags): Result<uint64, HostError>;
    receiveMessage(socket: SocketHandle, payload: &'a [uint8], control: &'b [uint8], handles: &'c [TransferredHandle], options: SocketReceiveMessageOptions): Result<SocketReceiveMessageResult, HostError>;
    sendMessage(socket: SocketHandle, payload: &'a readonly [uint8], message: &'b readonly SocketSendMessage): Result<uint64, HostError>;
    receiveBatch(socket: SocketHandle, requests: &'a [SocketReceiveBatchEntry], results: &'b [SocketReceiveMessageResult]): Result<uint64, HostError>;
    sendBatch(socket: SocketHandle, messages: &'a readonly [SocketSendBatchEntry]): Result<uint64, HostError>;
}
```

[language/library/src/net/binding/socket.ds:181:386](https://github.com/destack-sh/destack/blob/main/language/library/src/net/binding/socket.ds#L181-L386)

## Members

### `open(options: SocketOpenOptions): Result<SocketHandle, HostError>`

Create a socket.

### `pair(options: SocketOpenOptions): Result<SocketPair, HostError>`

Create a connected socket pair.

### `bind(socket: SocketHandle, address: &'a readonly SocketAddress): Result<void, HostError>`

Bind a socket to a local address.

### `listen(socket: SocketHandle, backlog: uint32): Result<void, HostError>`

Mark a bound stream socket as a listener.

### `accept(socket: SocketHandle, flags: SocketAcceptFlags): Result<SocketAcceptResult, HostError>`

Accept one connection from a listener socket.

### `connect(socket: SocketHandle, address: &'a readonly SocketAddress): Result<void, HostError>`

Connect a socket to a remote address.

### `close(socket: SocketHandle): Result<void, HostError>`

Close a socket handle.

### `shutdown(socket: SocketHandle, how: SocketShutdown): Result<void, HostError>`

Shut down a socket for reads, writes, or both.

### `setNonblocking(socket: SocketHandle, isEnabled: boolean): Result<void, HostError>`

Enable or disable nonblocking mode on a socket.

### `localAddress(socket: SocketHandle): Result<SocketAddress, HostError>`

Read the local socket address.

### `peerAddress(socket: SocketHandle): Result<SocketAddress, HostError>`

Read the remote socket address.

### `receive(socket: SocketHandle, buffer: &'a [uint8], flags: SocketMessageFlags): Result<uint64, HostError>`

Receive bytes from a socket.

### `send(socket: SocketHandle, buffer: &'a readonly [uint8], flags: SocketMessageFlags): Result<uint64, HostError>`

Send bytes to a socket.

### `receiveFrom(socket: SocketHandle, buffer: &'a [uint8], flags: SocketMessageFlags): Result<SocketReceiveFromResult, HostError>`

Receive bytes and source address from a socket.

### `sendTo(socket: SocketHandle, buffer: &'a readonly [uint8], address: &'b readonly SocketAddress, flags: SocketMessageFlags): Result<uint64, HostError>`

Send bytes to a destination address.

### `receiveMessage(socket: SocketHandle, payload: &'a [uint8], control: &'b [uint8], handles: &'c [TransferredHandle], options: SocketReceiveMessageOptions): Result<SocketReceiveMessageResult, HostError>`

Receive one message with ancillary data.

### `sendMessage(socket: SocketHandle, payload: &'a readonly [uint8], message: &'b readonly SocketSendMessage): Result<uint64, HostError>`

Send one message with ancillary data.

### `receiveBatch(socket: SocketHandle, requests: &'a [SocketReceiveBatchEntry], results: &'b [SocketReceiveMessageResult]): Result<uint64, HostError>`

Receive multiple messages into caller-owned buffers.

### `sendBatch(socket: SocketHandle, messages: &'a readonly [SocketSendBatchEntry]): Result<uint64, HostError>`

Send multiple messages from caller-owned buffers.
