CInternetServer::OnAccept Method  
 
virtual void OnAccept(
  SOCKET hSocket  
);

A virtual method that is invoked when a client attempts to connect to the server.

Parameters

hSocket
A handle to the server socket.

Return Value

None.

Remarks

The OnAccept event handler is invoked when a client attempts to connect to the server, but prior to the connection being accepted. To implement an event handler, the application should create a class derived from the CInternetServer class, and then override this method.

This event only occurs before the server has checked the active client limits. This event is typically used to reject a connection based on some criteria established by the server, such as the IP address of the client attempting to make the connection. To obtain the IP address of the client that is attempting to connect to the server, use the GetClientAddress method using the server handle.

If this event handler is not implemented, the server will permit the client connection to complete. To reject the connection attempt, call the Reject method using the handle to the server socket. Rejecting the client connection within the OnAccept event handler may cause unexpected behavior by the client application because the connection process will not complete normally. Instead of rejecting the client connection within the OnAccept handler, it is recommended that most server applications implement an OnConnect event handler, perform any required checks and then gracefully disconnect the client using the Disconnect method if needed.

Requirements

Minimum Desktop Platform: Windows 7 (Service Pack 1)
Minimum Server Platform: Windows Server 2008 R2 (Service Pack 1)
Header File: cswsock10.h
Import Library: cswskv10.lib
Unicode: Implemented as Unicode and ANSI versions.

See Also

Disconnect, OnConnect, OnDisconnect