# Client

<a id="client-3"></a>

# Client

```cpp
#include <icy/turn/client/client.h>

class Client
```

[Defined in src/turn/include/icy/turn/client/client.h:124](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L124)

> **Inherits:** [`Stateful< ClientState >`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful), [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation)
> **Subclassed by:** [`TCPClient`](https://auscaster.com/icey/docs/api-reference/icy-turn-TCPClient.md#tcpclient), [`UDPClient`](https://auscaster.com/icey/docs/api-reference/icy-turn-UDPClient.md#udpclient)

TURN client that manages relay allocations, permissions, and data relay via RFC 5766.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`Client`](#client-4) | `function` | Declared here |
| [`~Client`](#client-5) | `function` | Declared here |
| [`start`](#start-27) | `function` | Declared here |
| [`stop`](#stop-16) | `function` | Declared here |
| [`sendAllocate`](#sendallocate) | `function` | Declared here |
| [`addPermission`](#addpermission) | `function` | Declared here |
| [`addPermission`](#addpermission-1) | `function` | Declared here |
| [`sendCreatePermission`](#sendcreatepermission) | `function` | Declared here |
| [`sendChannelBind`](#sendchannelbind) | `function` | Declared here |
| [`sendRefresh`](#sendrefresh) | `function` | Declared here |
| [`sendData`](#senddata) | `function` | Declared here |
| [`handleResponse`](#handleresponse) | `function` | Declared here |
| [`handleAllocateResponse`](#handleallocateresponse) | `function` | Declared here |
| [`handleAllocateErrorResponse`](#handleallocateerrorresponse) | `function` | Declared here |
| [`handleCreatePermissionResponse`](#handlecreatepermissionresponse) | `function` | Declared here |
| [`handleCreatePermissionErrorResponse`](#handlecreatepermissionerrorresponse) | `function` | Declared here |
| [`handleRefreshResponse`](#handlerefreshresponse) | `function` | Declared here |
| [`handleDataIndication`](#handledataindication) | `function` | Declared here |
| [`transportProtocol`](#transportprotocol) | `function` | Declared here |
| [`createTransaction`](#createtransaction) | `function` | Declared here |
| [`authenticateRequest`](#authenticaterequest) | `function` | Declared here |
| [`sendAuthenticatedTransaction`](#sendauthenticatedtransaction) | `function` | Declared here |
| [`removeTransaction`](#removetransaction) | `function` | Declared here |
| [`mappedAddress`](#mappedaddress) | `function` | Declared here |
| [`relayedAddress`](#relayedaddress) | `function` | Declared here |
| [`closed`](#closed-7) | `function` | Declared here |
| [`observer`](#observer-1) | `function` | Declared here |
| [`options`](#options-9) | `function` | Declared here |
| [`addPermission`](#addpermission-2) | `function` | Declared here |
| [`addPermission`](#addpermission-3) | `function` | Declared here |
| [`hasPermission`](#haspermission) | `function` | Declared here |
| [`hasPermission`](#haspermission-1) | `function` | Declared here |
| [`removePermission`](#removepermission) | `function` | Declared here |
| [`removePermission`](#removepermission-1) | `function` | Declared here |
| [`_observer`](#_observer-1) | `variable` | Declared here |
| [`_options`](#_options-3) | `variable` | Declared here |
| [`_socket`](#_socket-3) | `variable` | Declared here |
| [`_timer`](#_timer-3) | `variable` | Declared here |
| [`_error`](#_error-7) | `variable` | Declared here |
| [`_mappedAddress`](#_mappedaddress) | `variable` | Declared here |
| [`_relayedAddress`](#_relayedaddress) | `variable` | Declared here |
| [`_realm`](#_realm) | `variable` | Declared here |
| [`_nonce`](#_nonce) | `variable` | Declared here |
| [`_pendingIndications`](#_pendingindications) | `variable` | Declared here |
| [`_transactions`](#_transactions) | `variable` | Declared here |
| [`setError`](#seterror-6) | `function` | Declared here |
| [`onSocketConnect`](#onsocketconnect-5) | `function` | Declared here |
| [`onSocketRecv`](#onsocketrecv-7) | `function` | Declared here |
| [`onSocketClose`](#onsocketclose-5) | `function` | Declared here |
| [`onTransactionProgress`](#ontransactionprogress) | `function` | Declared here |
| [`onStateChange`](#onstatechange-4) | `function` | Declared here |
| [`onTimer`](#ontimer-1) | `function` | Declared here |
| [`StateChange`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#statechange) | `variable` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful-1) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`~Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful-2) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`stateEquals`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateequals) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`stateBetween`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#statebetween) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`state`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#state-4) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`state`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#state-5) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`_state`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#_state) | `variable` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`beforeStateChange`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#beforestatechange) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`onStateChange`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#onstatechange-2) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`setState`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#setstate) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`setState`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#setstate-1) | `function` | Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful) |
| [`operator<<`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#operator-224) | `friend` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation-1) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`~IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation-2) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation-3) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#operator-225) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation-4) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#operator-226) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`updateUsage`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#updateusage) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`setLifetime`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#setlifetime) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`setBandwidthLimit`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#setbandwidthlimit) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`expired`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#expired-1) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`deleted`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#deleted-1) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`bandwidthLimit`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#bandwidthlimit) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`bandwidthUsed`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#bandwidthused) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`bandwidthRemaining`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#bandwidthremaining) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`timeRemaining`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#timeremaining) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`tuple`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#tuple) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`username`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#username-3) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`lifetime`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#lifetime-1) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`permissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#permissions) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`relayedAddress`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#relayedaddress-1) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`addPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermission-4) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`addPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermission-5) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`addPermissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermissions) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`removePermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removepermission-2) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`removePermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removepermission-3) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`removeAllPermissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removeallpermissions) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`removeExpiredPermissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removeexpiredpermissions) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`hasPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#haspermission-2) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`hasPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#haspermission-3) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`print`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#print-13) | `function` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_tuple`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_tuple) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_username`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_username-2) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_permissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_permissions) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_lifetime`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_lifetime) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_bandwidthLimit`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_bandwidthlimit) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_bandwidthUsed`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_bandwidthused) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_createdAt`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_createdat) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_updatedAt`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_updatedat) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |
| [`_deleted`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_deleted) | `variable` | Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation) |

## Inherited from [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful)

| Kind | Name | Description |
|------|------|-------------|
| `variable` | [`StateChange`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#statechange)  | Signals when the state changes. |
| `function` | [`Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful-1) `inline` |  |
| `function` | [`~Stateful`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateful-2) `virtual` `inline` |  |
| `function` | [`stateEquals`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#stateequals) `virtual` `const` `inline` | Returns true if the current state ID equals the given ID. |
| `function` | [`stateBetween`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#statebetween) `virtual` `const` `inline` | Returns true if the current state ID is in the inclusive range [lid, rid]. |
| `function` | [`state`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#state-4) `virtual` `inline` | Returns a mutable reference to the current state. |
| `function` | [`state`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#state-5) `virtual` `const` `inline` | Returns a copy of the current state. |
| `variable` | [`_state`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#_state)  |  |
| `function` | [`beforeStateChange`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#beforestatechange) `virtual` `inline` | Override to handle pre state change logic. Return false to prevent state change. |
| `function` | [`onStateChange`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#onstatechange-2) `virtual` `inline` | Override to handle post state change logic. |
| `function` | [`setState`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#setstate) `virtual` `inline` | Sets the state and sends the state signal if the state change was successful. |
| `function` | [`setState`](https://auscaster.com/icey/docs/api-reference/icy-Stateful.md#setstate-1) `virtual` `inline` | Sets the state and sends the state signal if the state change was successful. |

## Inherited from [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation)

| Kind | Name | Description |
|------|------|-------------|
| `friend` | [`operator<<`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#operator-224) `inline` |  |
| `function` | [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation-1)  |  |
| `function` | [`~IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation-2) `virtual` |  |
| `function` | [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation-3)  | Deleted constructor. |
| `function` | [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#operator-225)  | Deleted assignment operator. |
| `function` | [`IAllocation`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#iallocation-4)  | Deleted constructor. |
| `function` | [`operator=`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#operator-226)  | Deleted assignment operator. |
| `function` | [`updateUsage`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#updateusage) `virtual` | Updates the last-activity timestamp and accumulates bandwidth usage. Call this whenever data is relayed through the allocation. |
| `function` | [`setLifetime`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#setlifetime) `virtual` | Sets the allocation lifetime in seconds and resets the activity timestamp, effectively extending the expiry from the current moment. |
| `function` | [`setBandwidthLimit`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#setbandwidthlimit) `virtual` | Sets the maximum number of bytes this allocation may relay in its lifetime. Pass 0 to disable bandwidth limiting. |
| `function` | [`expired`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#expired-1) `virtual` `const` |  |
| `function` | [`deleted`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#deleted-1) `virtual` `const` | Returns true if the allocation's deleted flag is set and or if the allocation has expired. |
| `function` | [`bandwidthLimit`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#bandwidthlimit) `virtual` `const` |  |
| `function` | [`bandwidthUsed`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#bandwidthused) `virtual` `const` |  |
| `function` | [`bandwidthRemaining`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#bandwidthremaining) `virtual` `const` |  |
| `function` | [`timeRemaining`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#timeremaining) `virtual` `const` |  |
| `function` | [`tuple`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#tuple) `virtual` |  |
| `function` | [`username`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#username-3) `virtual` `const` |  |
| `function` | [`lifetime`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#lifetime-1) `virtual` `const` |  |
| `function` | [`permissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#permissions) `virtual` `const` |  |
| `function` | [`relayedAddress`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#relayedaddress-1) `virtual` `const` |  |
| `function` | [`addPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermission-4) `virtual` | Adds a permission for `ip`, or refreshes the existing one. |
| `function` | [`addPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermission-5) `virtual` | Adds a permission for `address`, or refreshes the existing one. The port is ignored; TURN permissions are IP-only. |
| `function` | [`addPermissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermissions) `virtual` | Adds (or refreshes) permissions for multiple IPs. |
| `function` | [`removePermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removepermission-2) `virtual` | Removes the permission for `ip` if present. |
| `function` | [`removePermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removepermission-3) `virtual` | Removes the permission for `address` if present. The port is ignored; TURN permissions are IP-only. |
| `function` | [`removeAllPermissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removeallpermissions) `virtual` | Removes all permissions from the list. |
| `function` | [`removeExpiredPermissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removeexpiredpermissions) `virtual` | Removes any permissions whose 5-minute lifetime has elapsed. |
| `function` | [`hasPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#haspermission-2) `virtual` | Checks whether a permission exists for `peerIP`. Local addresses (192.168.x.x and 127.x.x.x) are always permitted. |
| `function` | [`hasPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#haspermission-3) `virtual` | Checks whether a permission exists for `peerAddress`. The port is ignored; TURN permissions are IP-only. |
| `function` | [`print`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#print-13) `virtual` `const` `inline` |  |
| `variable` | [`_tuple`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_tuple)  |  |
| `variable` | [`_username`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_username-2)  |  |
| `variable` | [`_permissions`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_permissions)  |  |
| `variable` | [`_lifetime`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_lifetime)  |  |
| `variable` | [`_bandwidthLimit`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_bandwidthlimit)  |  |
| `variable` | [`_bandwidthUsed`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_bandwidthused)  |  |
| `variable` | [`_createdAt`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_createdat)  |  |
| `variable` | [`_updatedAt`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_updatedat)  |  |
| `variable` | [`_deleted`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#_deleted)  |  |

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Client`](#client-4)  |  |
|  | [`~Client`](#client-5) `virtual` |  |
| `void` | [`start`](#start-27) `virtual` | Connects the socket to the TURN server and starts the allocation sequence. Permissions must be added via [addPermission()](#addpermission) before calling this. |
| `void` | [`stop`](#stop-16) `virtual` | Stops the timer, cancels pending transactions, and closes the socket. |
| `void` | [`sendAllocate`](#sendallocate) `virtual` | Sends an Allocate request to the server with the configured transport and lifetime. On first call the server will typically respond with a 401 challenge; the client re-sends with credentials automatically. |
| `void` | [`addPermission`](#addpermission) `virtual` | Adds multiple peer IP addresses to the permission list. |
| `void` | [`addPermission`](#addpermission-1) `virtual` `override` | Adds a single peer IP to the permission list, or refreshes it if already present. Permissions should be added before [start()](#start-27); they may also be added later, in which case a new CreatePermission request is required. |
| `void` | [`sendCreatePermission`](#sendcreatepermission) `virtual` | Sends a CreatePermission request for all IPs currently in the permission list. Called automatically after allocation succeeds and periodically by the timer to refresh expiring permissions. |
| `void` | [`sendChannelBind`](#sendchannelbind) `virtual` | Channel bindings (RFC 5766 Section 11) are intentionally not implemented. They are a bandwidth optimization that replaces STUN-framed Send/Data indications with a compact 4-byte ChannelData header. This only benefits high-throughput media relay scenarios; in practice, media flows directly via ICE/DTLS rather than through this TURN client's data path, so the optimization is not worth the complexity (channel number allocation, 10-minute binding refresh timers, ChannelData wire framing). Data relay uses [sendData()](#senddata) with Send Indications instead. |
| `void` | [`sendRefresh`](#sendrefresh) `virtual` | Sends a Refresh request to extend the allocation lifetime. Called automatically by the timer when roughly one-third of the lifetime remains. |
| `void` | [`sendData`](#senddata) `virtual` | Sends a Send Indication to relay `data` to `peerAddress` through the TURN server. If permissions are still being negotiated the indication is queued and flushed once CreatePermission succeeds. |
| `bool` | [`handleResponse`](#handleresponse) `virtual` | Dispatches an incoming STUN/TURN response to the appropriate handler. |
| `void` | [`handleAllocateResponse`](#handleallocateresponse) `virtual` | Processes a successful Allocate response; extracts mapped/relayed addresses and advances the state to Authorizing, then sends CreatePermission. |
| `void` | [`handleAllocateErrorResponse`](#handleallocateerrorresponse) `virtual` | Handles an Allocate error response; manages the 401 challenge/re-send flow and sets the client to Failed for unrecoverable errors. |
| `void` | [`handleCreatePermissionResponse`](#handlecreatepermissionresponse) `virtual` | Handles a successful CreatePermission response; flushes queued Send Indications and advances state to Success. |
| `void` | [`handleCreatePermissionErrorResponse`](#handlecreatepermissionerrorresponse) `virtual` | Handles a failed CreatePermission response; clears all permissions and sets the client to Failed. |
| `void` | [`handleRefreshResponse`](#handlerefreshresponse) `virtual` | Handles a Refresh response; updates the stored lifetime. |
| `void` | [`handleDataIndication`](#handledataindication) `virtual` | Handles an incoming Data Indication; extracts peer address and data and forwards to [ClientObserver::onRelayDataReceived()](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientObserver.md#onrelaydatareceived). |
| `int` | [`transportProtocol`](#transportprotocol) `virtual` |  |
| [`stun::Transaction::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#ptr-21) | [`createTransaction`](#createtransaction) `virtual` | Creates a new STUN transaction, registers the progress callback, and adds it to the active transaction list. |
| `void` | [`authenticateRequest`](#authenticaterequest) `virtual` | Adds STUN long-term credential attributes (Username, Realm, Nonce, MessageIntegrity) to `request` if the realm has been received from the server. |
| `bool` | [`sendAuthenticatedTransaction`](#sendauthenticatedtransaction) `virtual` | Calls [authenticateRequest()](#authenticaterequest) then sends the transaction. |
| [`stun::Transaction::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#ptr-21) | [`removeTransaction`](#removetransaction) `virtual` | Removes a transaction from the active list. The [IntrusivePtr](https://auscaster.com/icey/docs/api-reference/icy-IntrusivePtr.md#intrusiveptr) keeps the object alive until the caller's copy is released. |
| [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) | [`mappedAddress`](#mappedaddress) `const` |  |
| [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) | [`relayedAddress`](#relayedaddress) `virtual` `const` `override` |  |
| `bool` | [`closed`](#closed-7) `const` |  |
| [`ClientObserver`](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientObserver.md#clientobserver) & | [`observer`](#observer-1)  |  |
| const [`Options`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client-Options.md#options-10) & | [`options`](#options-9) `const` |  |
| `void` | [`addPermission`](#addpermission-2) `virtual` | Adds a permission for `ip`, or refreshes the existing one. |
| `void` | [`addPermission`](#addpermission-3) `virtual` | Adds a permission for `address`, or refreshes the existing one. The port is ignored; TURN permissions are IP-only. |
| `bool` | [`hasPermission`](#haspermission) `virtual` | Checks whether a permission exists for `peerIP`. Local addresses (192.168.x.x and 127.x.x.x) are always permitted. |
| `bool` | [`hasPermission`](#haspermission-1) `virtual` | Checks whether a permission exists for `peerAddress`. The port is ignored; TURN permissions are IP-only. |
| `void` | [`removePermission`](#removepermission) `virtual` | Removes the permission for `ip` if present. |
| `void` | [`removePermission`](#removepermission-1) `virtual` | Removes the permission for `address` if present. The port is ignored; TURN permissions are IP-only. |

---

<a id="client-4"></a>

### Client

```cpp
Client(ClientObserver & observer, const Options & options, const net::Socket::Ptr & socket)
```

[Defined in src/turn/include/icy/turn/client/client.h:161](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L161)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `observer` | [`ClientObserver`](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientObserver.md#clientobserver) & | Observer to receive lifecycle and data callbacks. |
| `options` | const [`Options`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client-Options.md#options-10) & | [Configuration](https://auscaster.com/icey/docs/api-reference/icy-Configuration.md#configuration) for this client instance. |
| `socket` | const [`net::Socket::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-net-Socket.md#ptr-9) & | Underlying transport socket (TCP or UDP). |

---

<a id="client-5"></a>

### ~Client

`virtual`

```cpp
virtual ~Client()
```

[Defined in src/turn/include/icy/turn/client/client.h:162](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L162)

---

<a id="start-27"></a>

### start

`virtual`

```cpp
virtual void start()
```

[Defined in src/turn/include/icy/turn/client/client.h:166](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L166)

Connects the socket to the TURN server and starts the allocation sequence. Permissions must be added via [addPermission()](#addpermission) before calling this.

#### Reimplemented by

- [`TCPClient::start`](https://auscaster.com/icey/docs/api-reference/icy-turn-TCPClient.md#start-29)

---

<a id="stop-16"></a>

### stop

`virtual`

```cpp
virtual void stop()
```

[Defined in src/turn/include/icy/turn/client/client.h:169](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L169)

Stops the timer, cancels pending transactions, and closes the socket.

#### Reimplemented by

- [`TCPClient::stop`](https://auscaster.com/icey/docs/api-reference/icy-turn-TCPClient.md#stop-18)

---

<a id="sendallocate"></a>

### sendAllocate

`virtual`

```cpp
virtual void sendAllocate()
```

[Defined in src/turn/include/icy/turn/client/client.h:175](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L175)

Sends an Allocate request to the server with the configured transport and lifetime. On first call the server will typically respond with a 401 challenge; the client re-sends with credentials automatically.

---

<a id="addpermission"></a>

### addPermission

`virtual`

```cpp
virtual void addPermission(const IPList & peerIPs)
```

[Defined in src/turn/include/icy/turn/client/client.h:179](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L179)

Adds multiple peer IP addresses to the permission list.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `peerIPs` | const [`IPList`](https://auscaster.com/icey/docs/api-reference/icy-turn.md#iplist) & | List of IPv4 address strings to permit. |

---

<a id="addpermission-1"></a>

### addPermission

`virtual` `override`

```cpp
virtual void addPermission(const std::string & ip) override
```

[Defined in src/turn/include/icy/turn/client/client.h:186](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L186)

Adds a single peer IP to the permission list, or refreshes it if already present. Permissions should be added before [start()](#start-27); they may also be added later, in which case a new CreatePermission request is required.

#### Reimplements

- [`IAllocation::addPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermission-4)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `ip` | `const std::string &` | IPv4 address string of the permitted peer. |

---

<a id="sendcreatepermission"></a>

### sendCreatePermission

`virtual`

```cpp
virtual void sendCreatePermission()
```

[Defined in src/turn/include/icy/turn/client/client.h:191](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L191)

Sends a CreatePermission request for all IPs currently in the permission list. Called automatically after allocation succeeds and periodically by the timer to refresh expiring permissions.

---

<a id="sendchannelbind"></a>

### sendChannelBind

`virtual`

```cpp
virtual void sendChannelBind(const std::string & peerIP)
```

[Defined in src/turn/include/icy/turn/client/client.h:202](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L202)

Channel bindings (RFC 5766 Section 11) are intentionally not implemented. They are a bandwidth optimization that replaces STUN-framed Send/Data indications with a compact 4-byte ChannelData header. This only benefits high-throughput media relay scenarios; in practice, media flows directly via ICE/DTLS rather than through this TURN client's data path, so the optimization is not worth the complexity (channel number allocation, 10-minute binding refresh timers, ChannelData wire framing). Data relay uses [sendData()](#senddata) with Send Indications instead.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `peerIP` | `const std::string &` | Unused; always throws std::logic_error. |

---

<a id="sendrefresh"></a>

### sendRefresh

`virtual`

```cpp
virtual void sendRefresh()
```

[Defined in src/turn/include/icy/turn/client/client.h:207](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L207)

Sends a Refresh request to extend the allocation lifetime. Called automatically by the timer when roughly one-third of the lifetime remains.

---

<a id="senddata"></a>

### sendData

`virtual`

```cpp
virtual void sendData(const char * data, size_t size, const net::Address & peerAddress)
```

[Defined in src/turn/include/icy/turn/client/client.h:215](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L215)

Sends a Send Indication to relay `data` to `peerAddress` through the TURN server. If permissions are still being negotiated the indication is queued and flushed once CreatePermission succeeds.

#### Reimplemented by

- [`TCPClient::sendData`](https://auscaster.com/icey/docs/api-reference/icy-turn-TCPClient.md#senddata-1)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `data` | `const char *` | Pointer to the payload to relay. |
| `size` | `size_t` | Number of bytes to relay. |
| `peerAddress` | const [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) & | Destination peer address (must have an active permission). |

---

<a id="handleresponse"></a>

### handleResponse

`virtual`

```cpp
virtual bool handleResponse(const stun::Message & response)
```

[Defined in src/turn/include/icy/turn/client/client.h:220](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L220)

Dispatches an incoming STUN/TURN response to the appropriate handler. 
#### Returns
true if the message was handled, false if it was unrecognised.

#### Reimplemented by

- [`TCPClient::handleResponse`](https://auscaster.com/icey/docs/api-reference/icy-turn-TCPClient.md#handleresponse-1)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `response` | const [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) & | Received STUN message. |

---

<a id="handleallocateresponse"></a>

### handleAllocateResponse

`virtual`

```cpp
virtual void handleAllocateResponse(const stun::Message & response)
```

[Defined in src/turn/include/icy/turn/client/client.h:225](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L225)

Processes a successful Allocate response; extracts mapped/relayed addresses and advances the state to Authorizing, then sends CreatePermission.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `response` | const [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) & | Allocate success response from the server. |

---

<a id="handleallocateerrorresponse"></a>

### handleAllocateErrorResponse

`virtual`

```cpp
virtual void handleAllocateErrorResponse(const stun::Message & response)
```

[Defined in src/turn/include/icy/turn/client/client.h:230](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L230)

Handles an Allocate error response; manages the 401 challenge/re-send flow and sets the client to Failed for unrecoverable errors.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `response` | const [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) & | Allocate error response from the server. |

---

<a id="handlecreatepermissionresponse"></a>

### handleCreatePermissionResponse

`virtual`

```cpp
virtual void handleCreatePermissionResponse(const stun::Message & response)
```

[Defined in src/turn/include/icy/turn/client/client.h:235](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L235)

Handles a successful CreatePermission response; flushes queued Send Indications and advances state to Success.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `response` | const [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) & | CreatePermission success response from the server. |

---

<a id="handlecreatepermissionerrorresponse"></a>

### handleCreatePermissionErrorResponse

`virtual`

```cpp
virtual void handleCreatePermissionErrorResponse(const stun::Message & response)
```

[Defined in src/turn/include/icy/turn/client/client.h:240](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L240)

Handles a failed CreatePermission response; clears all permissions and sets the client to Failed.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `response` | const [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) & | CreatePermission error response from the server. |

---

<a id="handlerefreshresponse"></a>

### handleRefreshResponse

`virtual`

```cpp
virtual void handleRefreshResponse(const stun::Message & response)
```

[Defined in src/turn/include/icy/turn/client/client.h:244](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L244)

Handles a Refresh response; updates the stored lifetime.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `response` | const [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) & | Refresh response from the server. |

---

<a id="handledataindication"></a>

### handleDataIndication

`virtual`

```cpp
virtual void handleDataIndication(const stun::Message & response)
```

[Defined in src/turn/include/icy/turn/client/client.h:249](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L249)

Handles an incoming Data Indication; extracts peer address and data and forwards to [ClientObserver::onRelayDataReceived()](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientObserver.md#onrelaydatareceived).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `response` | const [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) & | Data Indication message from the server. |

---

<a id="transportprotocol"></a>

### transportProtocol

`virtual`

```cpp
virtual int transportProtocol()
```

[Defined in src/turn/include/icy/turn/client/client.h:253](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L253)

#### Returns
The IANA protocol number for the underlying transport (kProtocolUDP or kProtocolTCP).

#### Reimplemented by

- [`TCPClient::transportProtocol`](https://auscaster.com/icey/docs/api-reference/icy-turn-TCPClient.md#transportprotocol-1)

---

<a id="createtransaction"></a>

### createTransaction

`virtual`

```cpp
virtual stun::Transaction::Ptr createTransaction(const net::Socket::Ptr & socket = nullptr)
```

[Defined in src/turn/include/icy/turn/client/client.h:259](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L259)

Creates a new STUN transaction, registers the progress callback, and adds it to the active transaction list. 
#### Returns
[IntrusivePtr](https://auscaster.com/icey/docs/api-reference/icy-IntrusivePtr.md#intrusiveptr) to the new transaction.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `socket` | const [`net::Socket::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-net-Socket.md#ptr-9) & | Optional override socket; uses the control socket if nullptr. |

---

<a id="authenticaterequest"></a>

### authenticateRequest

`virtual`

```cpp
virtual void authenticateRequest(stun::Message & request)
```

[Defined in src/turn/include/icy/turn/client/client.h:264](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L264)

Adds STUN long-term credential attributes (Username, Realm, Nonce, MessageIntegrity) to `request` if the realm has been received from the server.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `request` | [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) & | Message to decorate with authentication attributes. |

---

<a id="sendauthenticatedtransaction"></a>

### sendAuthenticatedTransaction

`virtual`

```cpp
virtual bool sendAuthenticatedTransaction(stun::Transaction * transaction)
```

[Defined in src/turn/include/icy/turn/client/client.h:269](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L269)

Calls [authenticateRequest()](#authenticaterequest) then sends the transaction. 
#### Returns
true if the send succeeded.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `transaction` | [`stun::Transaction`](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#transaction-3) * | Transaction whose request to authenticate and send. |

---

<a id="removetransaction"></a>

### removeTransaction

`virtual`

```cpp
virtual stun::Transaction::Ptr removeTransaction(stun::Transaction * transaction)
```

[Defined in src/turn/include/icy/turn/client/client.h:275](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L275)

Removes a transaction from the active list. The [IntrusivePtr](https://auscaster.com/icey/docs/api-reference/icy-IntrusivePtr.md#intrusiveptr) keeps the object alive until the caller's copy is released. 
#### Returns
The removed Ptr, or nullptr if not found.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `transaction` | [`stun::Transaction`](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#transaction-3) * | Transaction to remove. |

---

<a id="mappedaddress"></a>

### mappedAddress

`const`

```cpp
net::Address mappedAddress() const
```

[Defined in src/turn/include/icy/turn/client/client.h:278](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L278)

#### Returns
The server-reflexive (mapped) address assigned by the TURN server.

---

<a id="relayedaddress"></a>

### relayedAddress

`virtual` `const` `override`

```cpp
virtual net::Address relayedAddress() const override
```

[Defined in src/turn/include/icy/turn/client/client.h:281](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L281)

#### Returns
The relayed transport address assigned by the TURN server.

#### Reimplements

- [`IAllocation::relayedAddress`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#relayedaddress-1)

---

<a id="closed-7"></a>

### closed

`const`

```cpp
bool closed() const
```

[Defined in src/turn/include/icy/turn/client/client.h:284](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L284)

#### Returns
true when the client is in the None or Failed state.

---

<a id="observer-1"></a>

### observer

```cpp
ClientObserver & observer()
```

[Defined in src/turn/include/icy/turn/client/client.h:287](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L287)

#### Returns
Reference to the observer provided at construction.

---

<a id="options-9"></a>

### options

`const`

```cpp
const Options & options() const
```

[Defined in src/turn/include/icy/turn/client/client.h:290](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L290)

#### Returns
Reference to the immutable options struct.

---

<a id="addpermission-2"></a>

### addPermission

`virtual`

```cpp
virtual void addPermission(const std::string & ip)
```

[Defined in src/turn/include/icy/turn/client/client.h:154](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L154)

Adds a permission for `ip`, or refreshes the existing one.

#### Reimplements

- [`IAllocation::addPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermission-4)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `ip` | `const std::string &` | IPv4 address string to permit. |

---

<a id="addpermission-3"></a>

### addPermission

`virtual`

```cpp
virtual void addPermission(const net::Address & address)
```

[Defined in src/turn/include/icy/turn/client/client.h:154](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L154)

Adds a permission for `address`, or refreshes the existing one. The port is ignored; TURN permissions are IP-only.

#### Reimplements

- [`IAllocation::addPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#addpermission-5)

---

<a id="haspermission"></a>

### hasPermission

`virtual`

```cpp
virtual bool hasPermission(const std::string & peerIP)
```

[Defined in src/turn/include/icy/turn/client/client.h:155](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L155)

Checks whether a permission exists for `peerIP`. Local addresses (192.168.x.x and 127.x.x.x) are always permitted. 
#### Returns
true if a valid (non-expired) permission exists.

#### Reimplements

- [`IAllocation::hasPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#haspermission-2)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `peerIP` | `const std::string &` | IPv4 address string to check. |

---

<a id="haspermission-1"></a>

### hasPermission

`virtual`

```cpp
virtual bool hasPermission(const net::Address & peerAddress)
```

[Defined in src/turn/include/icy/turn/client/client.h:155](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L155)

Checks whether a permission exists for `peerAddress`. The port is ignored; TURN permissions are IP-only.

#### Reimplements

- [`IAllocation::hasPermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#haspermission-3)

---

<a id="removepermission"></a>

### removePermission

`virtual`

```cpp
virtual void removePermission(const std::string & ip)
```

[Defined in src/turn/include/icy/turn/client/client.h:156](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L156)

Removes the permission for `ip` if present.

#### Reimplements

- [`IAllocation::removePermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removepermission-2)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `ip` | `const std::string &` | IPv4 address string to remove. |

---

<a id="removepermission-1"></a>

### removePermission

`virtual`

```cpp
virtual void removePermission(const net::Address & address)
```

[Defined in src/turn/include/icy/turn/client/client.h:156](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L156)

Removes the permission for `address` if present. The port is ignored; TURN permissions are IP-only.

#### Reimplements

- [`IAllocation::removePermission`](https://auscaster.com/icey/docs/api-reference/icy-turn-IAllocation.md#removepermission-3)

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`ClientObserver`](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientObserver.md#clientobserver) & | [`_observer`](#_observer-1)  |  |
| [`Options`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client-Options.md#options-10) | [`_options`](#_options-3)  |  |
| [`net::SocketEmitter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketEmitter.md#socketemitter) | [`_socket`](#_socket-3)  |  |
| [`Timer`](https://auscaster.com/icey/docs/api-reference/icy-Timer.md#timer) | [`_timer`](#_timer-3)  |  |
| [`icy::Error`](https://auscaster.com/icey/docs/api-reference/icy-Error.md#error) | [`_error`](#_error-7)  |  |
| [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) | [`_mappedAddress`](#_mappedaddress)  |  |
| [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) | [`_relayedAddress`](#_relayedaddress)  |  |
| `std::string` | [`_realm`](#_realm)  |  |
| `std::string` | [`_nonce`](#_nonce)  |  |
| std::deque< [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) > | [`_pendingIndications`](#_pendingindications)  | A list of queued Send indication packets awaiting server permissions. |
| std::vector< [`stun::Transaction::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#ptr-21) > | [`_transactions`](#_transactions)  | A list containing currently active transactions. |

---

<a id="_observer-1"></a>

### _observer

```cpp
ClientObserver & _observer
```

Type: [`ClientObserver`](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientObserver.md#clientobserver) &

[Defined in src/turn/include/icy/turn/client/client.h:324](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L324)

---

<a id="_options-3"></a>

### _options

```cpp
Options _options
```

Type: [`Options`](https://auscaster.com/icey/docs/api-reference/icy-turn-Client-Options.md#options-10)

[Defined in src/turn/include/icy/turn/client/client.h:325](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L325)

---

<a id="_socket-3"></a>

### _socket

```cpp
net::SocketEmitter _socket
```

Type: [`net::SocketEmitter`](https://auscaster.com/icey/docs/api-reference/icy-net-SocketEmitter.md#socketemitter)

[Defined in src/turn/include/icy/turn/client/client.h:326](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L326)

---

<a id="_timer-3"></a>

### _timer

```cpp
Timer _timer
```

Type: [`Timer`](https://auscaster.com/icey/docs/api-reference/icy-Timer.md#timer)

[Defined in src/turn/include/icy/turn/client/client.h:327](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L327)

---

<a id="_error-7"></a>

### _error

```cpp
icy::Error _error
```

Type: [`icy::Error`](https://auscaster.com/icey/docs/api-reference/icy-Error.md#error)

[Defined in src/turn/include/icy/turn/client/client.h:328](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L328)

---

<a id="_mappedaddress"></a>

### _mappedAddress

```cpp
net::Address _mappedAddress
```

Type: [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address)

[Defined in src/turn/include/icy/turn/client/client.h:329](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L329)

---

<a id="_relayedaddress"></a>

### _relayedAddress

```cpp
net::Address _relayedAddress
```

Type: [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address)

[Defined in src/turn/include/icy/turn/client/client.h:330](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L330)

---

<a id="_realm"></a>

### _realm

```cpp
std::string _realm
```

[Defined in src/turn/include/icy/turn/client/client.h:332](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L332)

---

<a id="_nonce"></a>

### _nonce

```cpp
std::string _nonce
```

[Defined in src/turn/include/icy/turn/client/client.h:333](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L333)

---

<a id="_pendingindications"></a>

### _pendingIndications

```cpp
std::deque< stun::Message > _pendingIndications
```

Type: std::deque< [`stun::Message`](https://auscaster.com/icey/docs/api-reference/icy-stun-Message.md#message-6) >

[Defined in src/turn/include/icy/turn/client/client.h:336](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L336)

A list of queued Send indication packets awaiting server permissions.

---

<a id="_transactions"></a>

### _transactions

```cpp
std::vector< stun::Transaction::Ptr > _transactions
```

Type: std::vector< [`stun::Transaction::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#ptr-21) >

[Defined in src/turn/include/icy/turn/client/client.h:339](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L339)

A list containing currently active transactions.

## Protected Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`setError`](#seterror-6) `virtual` | Sets the error field and transitions the client to the Failed state. |
| `bool` | [`onSocketConnect`](#onsocketconnect-5) `virtual` | Socket connect callback; starts the timer and sends the first Allocate request. |
| `bool` | [`onSocketRecv`](#onsocketrecv-7) `virtual` | Socket receive callback; parses STUN messages from the buffer and dispatches them. |
| `bool` | [`onSocketClose`](#onsocketclose-5) `virtual` | Socket close callback; shuts down the client and records the socket error. |
| `void` | [`onTransactionProgress`](#ontransactionprogress) `virtual` | STUN transaction state-change callback; handles Success and Failed outcomes. |
| `void` | [`onStateChange`](#onstatechange-4) `override` | Forwards state-change events to the observer. |
| `void` | [`onTimer`](#ontimer-1) `virtual` | Periodic timer callback; re-allocates on expiry or refreshes when lifetime is below one-third remaining. Also calls [ClientObserver::onTimer()](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientObserver.md#ontimer-2). |

---

<a id="seterror-6"></a>

### setError

`virtual`

```cpp
virtual void setError(const icy::Error & error)
```

[Defined in src/turn/include/icy/turn/client/client.h:295](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L295)

Sets the error field and transitions the client to the Failed state.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `error` | const [`icy::Error`](https://auscaster.com/icey/docs/api-reference/icy-Error.md#error) & | [Error](https://auscaster.com/icey/docs/api-reference/icy-Error.md#error) descriptor. |

---

<a id="onsocketconnect-5"></a>

### onSocketConnect

`virtual`

```cpp
virtual bool onSocketConnect(net::Socket & socket)
```

[Defined in src/turn/include/icy/turn/client/client.h:299](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L299)

Socket connect callback; starts the timer and sends the first Allocate request.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `socket` | [`net::Socket`](https://auscaster.com/icey/docs/api-reference/icy-net-Socket.md#socket-1) & | The connected socket. |

---

<a id="onsocketrecv-7"></a>

### onSocketRecv

`virtual`

```cpp
virtual bool onSocketRecv(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress)
```

[Defined in src/turn/include/icy/turn/client/client.h:305](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L305)

Socket receive callback; parses STUN messages from the buffer and dispatches them.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `socket` | [`net::Socket`](https://auscaster.com/icey/docs/api-reference/icy-net-Socket.md#socket-1) & | The receiving socket. |
| `buffer` | const [`MutableBuffer`](https://auscaster.com/icey/docs/api-reference/icy-MutableBuffer.md#mutablebuffer-6) & | Received data. |
| `peerAddress` | const [`net::Address`](https://auscaster.com/icey/docs/api-reference/icy-net-Address.md#address) & | Source address of the received data. |

---

<a id="onsocketclose-5"></a>

### onSocketClose

`virtual`

```cpp
virtual bool onSocketClose(net::Socket & socket)
```

[Defined in src/turn/include/icy/turn/client/client.h:309](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L309)

Socket close callback; shuts down the client and records the socket error.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `socket` | [`net::Socket`](https://auscaster.com/icey/docs/api-reference/icy-net-Socket.md#socket-1) & | The closed socket. |

---

<a id="ontransactionprogress"></a>

### onTransactionProgress

`virtual`

```cpp
virtual void onTransactionProgress(void * sender, TransactionState & state, const TransactionState &)
```

[Defined in src/turn/include/icy/turn/client/client.h:314](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L314)

STUN transaction state-change callback; handles Success and Failed outcomes.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `sender` | `void *` | Pointer to the [stun::Transaction](https://auscaster.com/icey/docs/api-reference/icy-stun-Transaction.md#transaction-3) that changed state. |
| `state` | [`TransactionState`](https://auscaster.com/icey/docs/api-reference/icy-TransactionState.md#transactionstate) & | The new transaction state. |

---

<a id="onstatechange-4"></a>

### onStateChange

`override`

```cpp
void onStateChange(ClientState & state, const ClientState & oldState) override
```

[Defined in src/turn/include/icy/turn/client/client.h:317](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L317)

Forwards state-change events to the observer.

---

<a id="ontimer-1"></a>

### onTimer

`virtual`

```cpp
virtual void onTimer()
```

[Defined in src/turn/include/icy/turn/client/client.h:321](https://github.com/auscaster/icey/blob/main/src/turn/include/icy/turn/client/client.h#L321)

Periodic timer callback; re-allocates on expiry or refreshes when lifetime is below one-third remaining. Also calls [ClientObserver::onTimer()](https://auscaster.com/icey/docs/api-reference/icy-turn-ClientObserver.md#ontimer-2).
