InetSetServerData Function  
 
BOOL WINAPI InetSetServerData(
  SOCKET hServer,  
  LPVOID lpvData  
);

The InetSetServerData function sets the application defined data associated with the specified server.

Parameters

hServer
The socket handle.
lpvData
Pointer to the application defined data associated with the specified server.

Return Value

If the function succeeds, the return value is non-zero. A return value of zero indicates that application defined data for the server could not be modified. To get extended error information, call InetGetLastError.

Remarks

The InetSetServerData function is used to associate application defined data with a specific server. A pointer to the data can be retrieved using the InetGetServerData function.

You should never specify a pointer to a local variable or data structure that will go out of scope when the calling function exits. If you do this, the pointer will no longer be valid after the function exits and attempting to dereference that pointer at some later time can cause an exception to be thrown and terminate the program. You should always allocate a block of memory for the data using a function such as HeapAlloc or LocalAlloc. If you specify the address of a static or global data structure, you must use thread synchronization functions when dereferencing and modifying that structure.

This function can only be used with server socket handles created using the InetServerStart function. It cannot be used with socket handles created using the InetListen or InetListenEx functions.

Example

UINT *pnValue1 = (UINT *)LocalAlloc(LPTR, sizeof(UINT));
UINT *pnValue2 = NULL;

*pnValue1 = 1234;

if (InetSetServerData(hServer, pnValue1) == FALSE)
{
    // Unable to associate the data with this server
    return;
}

if (InetGetServerData(hServer, &pnValue2) == FALSE)
{
    // Unable to retrieve the data associated with this server
    return;
}

// *pnValue2 == 1234
printf("The value of 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: cswsock11.h
Import Library: cswskv11.lib

See Also

InetGetClientData, InetGetServerData, InetSetClientData