Exemple #1
0
        /// <summary>
        /// On web context.
        /// </summary>
        /// <param name="sender">The server that sent the context.</param>
        /// <param name="context">The current connection context.</param>
        private void Server_OnWebContext(object sender, WebContext context)
        {
            Nequeo.Net.Data.ConnectionContext conn = null;

            lock (_lockObject)
            {
                // As data comes from the client send it to the load balance server
                // this client is connected to.
                conn = _clients[context.ConnectionID];
            }

            // If the client has been found.
            if (conn != null)
            {
                Nequeo.Net.NetClient client = conn.Client;

                // Read all the bytes in the buffer.
                int    count  = (int)context.WebRequest.Input.Length;
                byte[] buffer = new byte[count];
                context.WebRequest.Read(buffer, 0, count);

                if (buffer != null)
                {
                    // Write all the bytes to the balance server through the client.
                    client.Send(buffer);
                }

                buffer = null;
            }
        }
Exemple #2
0
        /// <summary>
        /// Initialise.
        /// </summary>
        private void Initialise()
        {
            // Select the connection level.
            switch (_connectionLevel)
            {
            case 2:
                // Assign the on connect action handler.
                _client = new Nequeo.Net.NetClient(_requestUri.Host, (_port > -1 ? _port : _requestUri.Port));
                break;

            case 1:
                // Assign the on connect action handler.
                _client = new Nequeo.Net.NetClient(_address, _port);
                break;

            case 0:
            default:
                // Assign the on connect action handler.
                _client = new Nequeo.Net.NetClient(_hostNameOrAddress, _port);
                break;
            }

            _client.Timeout                = 10;
            _client.HeaderTimeout          = 30000;
            _client.RequestTimeout         = 30000;
            _client.ResponseTimeout        = 30000;
            _client.ReadBufferSize         = 32768;
            _client.WriteBufferSize        = 32768;
            _client.ResponseBufferCapacity = 100000000;
            _client.RequestBufferCapacity  = 100000000;
            _client.UseSslConnection       = _isSecureConnection;
            _client.ValidateSslCertificate = _validateSslCertificate;
            _client.OnNetContext          += ManagerClient_OnNetContext;
        }
Exemple #3
0
        /// <summary>
        /// On client diconnected.
        /// </summary>
        /// <param name="context">The client context.</param>
        private async void ClientDisconnectedEx(Nequeo.Net.Provider.ISingleContextBase context)
        {
            await Nequeo.Threading.AsyncOperationResult <bool> .
            RunTask(() =>
            {
                lock (_lockObject)
                {
                    try
                    {
                        // Get the client.
                        Nequeo.Net.Data.ConnectionContext conn = _clients[context.ConnectionID];

                        // Close the connection.
                        Nequeo.Net.NetClient client = conn.Client;
                        client.Dispose();

                        // Remove the client.
                        _clients.Remove(context.ConnectionID);

                        // Decrement the server count. Find the current load balance server
                        // this client is connected to.
                        IEnumerable <Data.contextServer> balanceServers =
                            _loadServers.servers.Where(u => u.name.ToLower() == conn.LoadBalanceServer.ToLower());

                        // If the server has been found.
                        if (balanceServers.Count() > 0)
                        {
                            // Get the first server.
                            Data.contextServer balanceServer = balanceServers.First();

                            // Get the current client count.
                            int currentCount = balanceServer.count;

                            // If the current count is not zero
                            // then decrement to count else do
                            // not go less than zero.
                            if (currentCount > 0)
                            {
                                balanceServer.count = currentCount - 1;
                            }
                        }
                    }
                    catch { }
                }
            });
        }
Exemple #4
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.  If disposing
        /// equals true, the method has been called directly or indirectly by a user's
        /// code. Managed and unmanaged resources can be disposed.  If disposing equals
        /// false, the method has been called by the runtime from inside the finalizer
        /// and you should not reference other objects. Only unmanaged resources can
        /// be disposed.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    if (_callback != null)
                    {
                        _callback.Clear();
                    }

                    if (_state != null)
                    {
                        _state.Clear();
                    }

                    if (_client != null)
                    {
                        _client.Dispose();
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _lockConnectObject = null;
                _lockRequestObject = null;

                _callback = null;
                _state    = null;
                _client   = null;
            }
        }