/// <summary>
        /// Constructor for SocketServer Supppor
        /// </summary>
        /// <param name="server">A Reference to the parent SocketServer</param>
        /// <param name="wrappedSocket">RetType: The Socket object we are encapsulating</param>
        /// <param name="sizeOfRawBuffer">The size of the raw buffer</param>
        /// <param name="messageHandler">Reference to the user defined message handler function</param>
        /// <param name="closeHandler">Reference to the user defined close handler function</param>
        /// <param name="errorHandler">Reference to the user defined error handler function</param>
        public AdkSocketConnection(
            AdkSocketBinding server,
            IConnectedSocket wrappedSocket,
            int sizeOfRawBuffer,
            AdkSocketMessageHandler messageHandler,
            AdkSocketMessageHandler closeHandler,
            AdkSocketErrorHandler errorHandler
            )
        {
            // Create the raw buffer
            fRawBufferSize = sizeOfRawBuffer;
            fRawBuffer = new Byte[sizeOfRawBuffer];

            // Set the handler functions
            fMessageHandler = messageHandler;
            fCloseHandler = closeHandler;
            fErrorHandler = errorHandler;

            // Set the async socket function handlers
            fReadCompleteCallback = new AsyncCallback( ReceiveComplete );

            // Set reference to SocketServer
            fSocketServer = server;

            // Init the socket references
            fWrappedSocket = wrappedSocket;

            // Init the NetworkStream reference
            fStream = fWrappedSocket.CreateStream( FileAccess.ReadWrite, false );

            // Set these socket options
            fWrappedSocket.SetSocketOption
                ( SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, sizeOfRawBuffer );
            fWrappedSocket.SetSocketOption
                ( SocketOptionLevel.Socket, SocketOptionName.SendBuffer, sizeOfRawBuffer );
            fWrappedSocket.SetSocketOption
                ( SocketOptionLevel.Socket, SocketOptionName.DontLinger, 1 );
            fWrappedSocket.SetSocketOption( SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1 );

            // Wait for a message
            Receive();
        }
        /// <summary>
        /// Constructor for SocketServer Supppor
        /// </summary>
        /// <param name="server">A Reference to the parent SocketServer</param>
        /// <param name="wrappedSocket">RetType: The Socket object we are encapsulating</param>
        /// <param name="sizeOfRawBuffer">The size of the raw buffer</param>
        /// <param name="messageHandler">Reference to the user defined message handler function</param>
        /// <param name="closeHandler">Reference to the user defined close handler function</param>
        /// <param name="errorHandler">Reference to the user defined error handler function</param>
        public AdkSocketConnection(
            AdkSocketBinding server,
            IConnectedSocket wrappedSocket,
            int sizeOfRawBuffer,
            AdkSocketMessageHandler messageHandler,
            AdkSocketMessageHandler closeHandler,
            AdkSocketErrorHandler errorHandler
            )
        {
            // Create the raw buffer
            fRawBufferSize = sizeOfRawBuffer;
            fRawBuffer     = new Byte[sizeOfRawBuffer];

            // Set the handler functions
            fMessageHandler = messageHandler;
            fCloseHandler   = closeHandler;
            fErrorHandler   = errorHandler;

            // Set the async socket function handlers
            fReadCompleteCallback = new AsyncCallback(ReceiveComplete);

            // Set reference to SocketServer
            fSocketServer = server;

            // Init the socket references
            fWrappedSocket = wrappedSocket;

            // Init the NetworkStream reference
            fStream = fWrappedSocket.CreateStream(FileAccess.ReadWrite, false);

            // Set these socket options
            fWrappedSocket.SetSocketOption
                (SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, sizeOfRawBuffer);
            fWrappedSocket.SetSocketOption
                (SocketOptionLevel.Socket, SocketOptionName.SendBuffer, sizeOfRawBuffer);
            fWrappedSocket.SetSocketOption
                (SocketOptionLevel.Socket, SocketOptionName.DontLinger, 1);
            fWrappedSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);

            // Wait for a message
            Receive();
        }
        private void ConfigureSocketListener( AdkSocketBinding listener, IZone zone, int port, IPAddress address )
        {
            listener.HostAddress = address;
            listener.Port = port;
            listener.RawBufferSize = zone.Properties.MaxBufferSize + 512;

            // TT 1440 Add support for a "Max-Connections" feature in the ADK
            // This is currently an experimental, undocumented and untested feature.
            // See http://jetty.mortbay.org/jetty5/doc/optimization.html for more
            // information on optimization with Jetty
            HttpProperties httpProps = (HttpProperties) fProps;
            int maxRequestThreads = httpProps.MaxConnections;
            if ( maxRequestThreads > 0 )
            {
                listener.MaxClientConnections = maxRequestThreads;

                // No support in the .NET ADK yet for these features

                //			int minRequestThreads = httpProps.getMinConnections();
                //			if (minRequestThreads < 0) {
                //				minRequestThreads = (int) Math.ceil(maxRequestThreads / 5);
                //			}
                //			listener.setMinThreads(minRequestThreads);
                //
                //			int maxIdleTimeMs = httpProps.getMaxIdleTimeMs();
                //			if (maxIdleTimeMs > 0) {
                //				listener.setMaxIdleTimeMs(maxIdleTimeMs);
                //			}
                //			int lowResourcesPersistTimeMs = httpProps
                //					.getLowResourcesPersistTimeMs();
                //			if (lowResourcesPersistTimeMs > 0) {
                //				listener.setLowResourcePersistTimeMs(lowResourcesPersistTimeMs);
                //			}

                if ( (Adk.Debug & AdkDebugFlags.Transport) != 0 && log.IsDebugEnabled )
                {
                    log.Debug( "Set HttpListener.maxThreads to " + maxRequestThreads );
                    //				if (minRequestThreads > 0) {
                    //					log.Debug("Set HttpListener.minThreads to " + minRequestThreads );
                    //				}
                    //				if (maxIdleTimeMs > 0) {
                    //					log.Debug("Set HttpListener.maxIdleTimeMs to " + maxIdleTimeMs );
                    //				}
                    //				if (lowResourcesPersistTimeMs > 0) {
                    //					log.Debug("Set HttpListener.lowResourcesPersistTimeMs to " + lowResourcesPersistTimeMs );
                    //				}
                }
            }
        }