GetConnectedClients

EndPoint[] GetConnectedClients()
  • Description: The GetConnectedClients() method returns a list of all clients currently connected to the server, including their IP addresses and port information. This method allows the server to track which clients are connected and provides access to their connection details. It is particularly useful in multi-client servers for monitoring the connected clients.

  • Parameters: This method does not take any parameters.

  • Returns: The method returns an array of EndPoint[]. Each EndPoint object represents the IP address and port information of a connected client.


Important Notes:

  • This method is only applicable to connection-oriented protocols (such as TCP).

  • It does not work with UDP servers, as UDP is a connectionless protocol.

  • The GetConnectedClients() method helps in monitoring the active connections and the status of connected clients.


Usages:

The GetConnectedClients() method is used to retrieve the list of clients currently connected to the server. The returned EndPoint[] array contains connection information for each client. This allows server administrators to monitor connected clients and intervene when necessary.

EndPoint[] connectedClients = _serverConnectionsProvider.GetConnectedClients();
for (int index = 0; index < connectedClients.Length; index++)
{
    Console.WriteLine($"Client connected: {connectedClients[index]}");
}

Operations:

  • Retrieves the connection details of all connected clients.

  • Provides the ability to monitor and manage client connections.

  • Often used for connection management and monitoring client activity.

Last updated