CHttpServer::AsyncNotify Method  
 
BOOL AsyncNotify(
  HWND hWnd,  
  UINT uMsg  
);

Enable or disable asynchronous notification of changes in server status.

Parameters

hWnd
A handle to the window whose window procedure will receive the notification message.
uMsg
The user-defined message that will be sent to the notification window.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call the GetLastError method.

Remarks

The AsyncNotify method is used by an application to enable or disable asynchronous notifications. The message window is typically the main UI window and these notifications are used signal to the application that it should update the user interface. If the hWnd parameter is not NULL, it must specify a valid window handle and the user-defined message must have a value of WM_USER or higher. The application cannot specify a notification message that is reserved by the operating system. The pseudo-handle HWND_BROADCAST cannot be specified as the notification window. If the hWnd parameter is NULL, notifications for the specified server will be disabled.

When asynchronous notifications are enabled for a server, the server will post the user-defined message to the window whenever there is a change in status or after a client has connected or disconnected from the server. The wParam message parameter will contain the notification message and the lParam message parameter will contain the handle to the server or the client ID. The following notification messages are defined:

Value Description
HTTP_NOTIFY_STARTUP This notification is sent when the server has started and is preparing to accept client connections. This notification is only sent once, and only if asynchronous notifications are enabled immediately after the Start method is called. This message will not be sent once the server has begun accepting client connections or when notification messages are disabled and then subsequently re-enabled at a later time. The lParam message parameter will specify the handle to the server.
HTTP_NOTIFY_LISTEN This notification is sent when the server is listening for client connections. This notification message may be sent to the application multiple times over the lifetime of the server. If the server was suspended, this notification will be sent after the application calls the Resume method to resume accepting client connections. The lParam message parameter will specify the handle to the server.
HTTP_NOTIFY_SUSPEND This notification is sent when the server suspends accepting new connections because the application has called the Suspend method. This notification message may be sent to the application multiple times over the lifetime of the server. The lParam message parameter will specify the handle to the server.
HTTP_NOTIFY_RESTART This notification is sent when the server is restarted using the Restart method. Note that the server socket handle provided by the lParam message parameter will specify the new socket handle of the restarted server instance, not the original socket handle. The lParam message parameter will specify the handle to the server.
HTTP_NOTIFY_CONNECT This notification is sent when the server accepts a client connection and the thread that manages the client session has begun processing network events for that client. This message notification will not be sent if the client connection is rejected by the server. The lParam message parameter will specify the unique ID of the client that connected to the server.
HTTP_NOTIFY_DISCONNECT This notification is sent when the client disconnects from the server and the client socket has been closed. This notification message may not occur for each client session that is forced to terminate as the result of the server being stopped using the Stop method. The lParam message parameter will specify the unique ID of the client that disconnected from the server.
HTTP_NOTIFY_SHUTDOWN This notification is sent when the server thread is in the process of terminating. At the time the application processes this notification message, the server handle in lParam will reference the defunct server and cannot be used with other server methods. The lParam message parameter will specify the handle to the server.

If asynchronous notifications are enabled, you should never use those notifications as a replacement for an event handler. When an event occurs, the callback function that handles the event is invoked in the context of the thread that manages the client session. The application should exchange data with the client within that event handler and not in response to a notification message. These notification messages should only be used to update the application UI in response to changes in the status of the server.

The HTTP_NOTIFY_CONNECT and HTTP_NOTIFY_DISCONNECT notifications are different from the other server notifications because the lParam message parameter does not specify the server handle, but rather the unique client ID associated with the session that connected to or disconnected from the server. Use the GetClientServer method to obtain a handle to the server that created the client session. Note that at the time the application processes the HTTP_NOTIFY_DISCONNECT notification message, the client session will have already terminated.

Requirements

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

See Also