| INT 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 specifies 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. If the function fails, the
return value is INET_ERROR. To get extended error information, call
InetGetLastError.
Remarks
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.
If the nMaxClients parameter is less than the number of
active client connections, the function will fail and the last
error code will be set to the error ST_ERROR_BUFFER_TOO_SMALL. 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.
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
Client: Requires Windows Vista, Windows XP or Windows
2000 Professional.
Server: Requires Windows Server 2008, Windows Server 2003 or
Windows 2000 Server.
Header: Include cswsock6.h.
Library: Use cswskav6.lib.
See Also
InetServerBroadcast,
InetServerStart
|