# IServerConnectionsProvider

`IServerConnectionsProvider` is an interface designed for connection-oriented protocols, particularly TCP. This interface monitors the status of connected clients, tracks connection usage, and triggers events related to connection changes.

#### Purpose:

* **Monitoring Connection Status**: `IServerConnectionsProvider` tracks the status of clients that establish a connection. This includes scenarios where clients connect or disconnect from the server.
* **Monitoring Resource Usage**: It also tracks the connection usage and resource consumption of connected clients.

***

#### Supported Protocols:

* **TCP Protocol**: TCP is a connection-oriented protocol that ensures reliable data transmission. It allows the server to monitor the status of connected clients and the connection usage.

`IServerConnectionsProvider` supports only the TCP protocol, as this protocol requires establishing a connection and provides the ability to track connection statuses. UDP, being a connectionless protocol, is not supported by the `IServerConnectionsProvider` interface.

***

**Converting from ISocketServer to IServerConnectionsProvider:**

The `IServerConnectionsProvider` interface may be derived from the `ISocketServer` interface. To transition from `ISocketServer` to `IServerConnectionsProvider`, you can use a classic type casting. This allows you to access the features of `IServerConnectionsProvider` from a specific `socketServer` instance.

**Type Casting Example:**

```csharp
if (_socketServer is IServerConnectionsProvider provider) 
{ 
    _serverConnectionsProvider = provider; 
}
```

This code snippet checks if the `socketServer` instance supports the `IServerConnectionsProvider` interface. If it does, the type casting is done, and you can access information such as client connection status and resource usage through this instance.

***

**Additional Event:**

* **OnClientConnectionChanged:**\
  This event is triggered when a client connects or disconnects from the server. The event handler receives the EndPoint (representing the client’s address) and a boolean value indicating whether the client has connected (`true`) or disconnected (`false`)

```csharp
_serverConnectionsProvider.OnClientConnectionChanged += (endPoint, isConnected) =>
{
    Console.WriteLine($"Client {endPoint} => isConnected: {isConnected}");
};
```

***

**Operations:**

The **IServerConnectionsProvider** interface provides essential functions for monitoring client connections and tracking server resource usage. These functionalities are vital for managing and maintaining the performance of a server handling client connections. The interface allows you to retrieve the list of connected clients and monitor the connection usage rate.

These operations depend on the proper configuration of the server to function effectively and provide accurate data on connected clients and resource utilization.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tariksavas.gitbook.io/tarnet/docs/how-to-use/iserverconnectionsprovider.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
