INT WINAPI InetEnumServerClients( |
|
SOCKET hServer, |
|
|
SOCKET *lpClients, |
|
|
INT nMaxClients |
|
); |
The InetEnumServerClients function returns a list of active
client sessions established with the specified server.
Parameters
- hServer
- Handle to the server socket.
- lpClients
- Pointer to an array of socket handles which identifies all
client connections. If this parameter is NULL, then the function
will return the number of active client connections established
with the server.
- nMaxClients
- Maximum number of client socket handles to be returned. If the
lpClients parameter is NULL, this parameter should be
specified with a value of zero.
Return Value
If the function succeeds, the return value is the number of active
client connections to the server. A return value of zero indicates
that there are no active client sessions. If the function fails, the return
value is INET_ERROR. To get extended error information, call
InetGetLastError.
Remarks
If the nMaxClients parameter is less than the number of
active client connections, the function will fail. To dynamically
determine the number of active connections, call the function with
the lpClients parameter with a value of NULL, and the
nMaxClients parameter with a value of zero. To enumerate the
active clients that match a specific IP address, use the
InetEnumServerClientsByAddress function.
This function will not enumerate clients that have disconnected
from the server, even if the session thread is still active. If the
server is in the process of shutting down, this function will return
zero, indicating no active client sessions, even though there may be
clients that are still in the process of disconnecting from the
server. To determine the actual number of client sessions regardless
of their status, use the InetGetClientThreads function.
The socket handle for the server must be one that was created
using the InetServerStart function, and cannot be a socket
that was created using InetListen or InetListenEx.
Example
INT nMaxClients = InetEnumServerClients(hServer, NULL, 0);
if (nMaxClients > 0)
{
SOCKET *lpClients = NULL;
// Allocate memory for client sockets
lpClients = (SOCKET *)LocalAlloc(LPTR, nMaxClients * sizeof(SOCKET));
if (lpClients == NULL)
{
// Virtual memory has been exhausted
return;
}
nMaxClients = InetEnumServerClients(hServer, lpClients, nMaxClients);
if (nMaxClients == INET_ERROR)
{
// Unable to obtain list of connected clients
return;
}
for (INT nClient = 0; nClient < nMaxClients; nClient++)
{
// Perform some action with each client socket
SOCKET hClient = lpClients[nClient];
}
// Free memory allocated for client sockets
LocalFree((HLOCAL)lpClients);
}
Requirements
Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cswsock11.h
Import Library: cswskv11.lib
See Also
InetEnumServerClientsByAddress,
InetGetClientThreads,
InetServerBroadcast,
InetServerStart
|