CInternetServer::GetClientData Method  
 
BOOL GetClientData(
  SOCKET hClient,  
  LPVOID *lppvData  
);
BOOL GetClientData(
  LPVOID *lppvData  
);

Returns the application defined data associated with the specified client session.

Parameters

hClient
An optional parameter that specifies the handle to the client socket. If this parameter is omitted, the socket handle for the active client session will be used. If this method is called outside of a server event handler, the socket handle must be specified.
lppvData
A pointer to a void pointer which will contain an application defined value associated with the client session.

Return Value

If the method succeeds, the return value is non-zero. A return value of zero indicates that application defined data for the client session could not be retrieved. To get extended error information, call GetLastError.

Remarks

The GetClientData method is used to retrieve the application defined data that was previously associated with a client session using the SetClientData method. This is typically used to associate a pointer to a data structure or a class instance with a specific client handle.

This method can only be used with client socket handles created using the server interface. If the socket handle is invalid, or does not reference a client socket handle created by the server, the lppvData pointer passed to this method will be initialized to a value of NULL and the method will return a value of zero.

If this method is called with a valid socket handle and there is no data associated with the socket, the method will return a non-zero value and the lppvData pointer will be returned with a NULL value. Before dereferencing the pointer returned by this method, the application should always check the return value to ensure the method succeeded and make sure that the pointer is not NULL.

Example

UINT *pnValue1 = new UINT;
UINT *pnValue2 = NULL;

*pnValue1 = 1234;

if (!pServer->SetClientData(hClient, pnValue1))
{
    // Unable to associate the data with this session
    return;
}

if (!pServer->GetClientData(hClient, (LPVOID *)&pnValue2))
{
    // Unable to retrieve the data associated with this session
    return;
}

// pnValue2 == pnValue1
printf("The value of the user defined data is %u\n", *pnValue2);

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cswsock12.h
Import Library: cswskv12.lib

See Also