Managing server connection handlers

## Managing server connection handlers

Before connecting to a TeamSpeak 3 server, a new server connection handler needs to be spawned. Each handler is identified by a unique ID (usually called `serverConnectionHandlerID`). With one server connection handler a connection can be established and dropped multiple times, so for simply reconnecting to the same or another server no new handler needs to be spawned but existing ones can be reused. However, for using multiple connections simultaneously a new handler has to be spawned for each connection.

To create a new server connection handler and receive its ID, call

`unsigned int ts3client_spawnNewServerConnectionHandler(` | port, |
| result`)`; |

`int port`;
`uint64* result`;

Parameters

- `port`

  Port the client should bind on. Specify zero to let the operating system chose any free port. In most cases passing zero is the best choice.

  If `port` is specified, the function return value should be checked for `ERROR_unable_to_bind_network_port`. Handle this error by switching to an alternative port until a "free" port is hit and the function returns `ERROR_ok`.

  | Caution
  Do not specify a non-zero value for `port` unless you absolutely need a specific port. Passing zero is the better way in most use cases.

- `result`

  Address of a variable that receives the server connection handler ID.

To destroy a server connection handler, call

`unsigned int ts3client_destroyServerConnectionHandler(` | serverConnectionHandlerID`)`; |

`uint64 serverConnectionHandlerID`;

Parameters

- `serverConnectionHandlerID`

  ID of the server connection handler to destroy.

Both functions return `ERROR_ok` on success, otherwise an error code as defined in `public_errors.h`.

| Important
Destroying invalidates the handler ID, so it must not be used anymore afterwards. Also do not destroy a server connection handler ID from within a callback.

Shutting down |  | Connecting to a server