The OnConnect event handler is invoked after the client has
connected to the server. To implement
an event handler, the application should create a class derived from
the CHttpServer class, and then override this method.
This event only occurs after the server has checked the active
client limits and has accepted the connection. If the server was
started with security enabled, the TLS handshake has been performed.
If the server has been suspended, or the limit on
the maximum number of client sessions has been exceeded, the server
will terminate the client session prior to this event handler being invoked.
If this event handler is not implemented, the server will perform
the default action of accepting the connection and waiting for the
client to send a request for a document. To reject a connection, call the DisconnectClient method to terminate
the client session.
Your server application should never make the assumption that for
each OnConnect event there will be one command issued by the
client. A client may issue multiple commands per session, and in some
cases a client may send no commands to the server. If the client is
using HTTP 1.0, connections will not be persistent. This means that
the client will connect to the server, issue one command and then
disconnect. For clients that use HTTP 1.1, multiple commands may be
issued using a single connection. There is no guarantee that either
the client or server will maintain a persistent connection, and either
may request that the connection be closed after a command has
completed.
If the client is a web browser, it is not unusual to see multiple,
simultaneous connections being established with your server for a single
request. Do not be concerned if you see multiple connections without
any commands being issued. Browsers will do this to in anticipation of
downloading additional assets (stylesheets, images, etc.) to improve
performance and will typically close any unused connections after a few seconds.
You may also see multiple requests for the file /favicon.ico
.
The browser will request this icon to display in the browser address bar and
bookmarks. If the file does not exist, the browser ignores the error
response from the server.