Ejemplo n.º 1
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 (_socketServer != null)
                    {
                        _socketServer.Dispose();
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _socketServer        = null;
                _multiEndpointModels = null;
                _addressesV4         = null;
                _addressesV6         = null;
                _sslAddressesV4      = null;
                _sslAddressesV6      = null;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create the server.
 /// </summary>
 private void CreateServer()
 {
     // If the server has not been created.
     if (_socketServer == null)
     {
         // Create the server from the configuration details.
         _socketServer = new Nequeo.Net.Provider.UdpSingleServerEndpoint(_multiEndpointModels, _maxNumClients);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Start the server listener.
        /// </summary>
        public virtual void Start()
        {
            try
            {
                // If not listening.
                if (!_isListening)
                {
                    // Initialise the server.
                    Initialisation();

                    // If created.
                    if (_socketServer != null)
                    {
                        // Start the servers.
                        _socketServer.Start();

                        // Search for errors.
                        foreach (Exception exception in _socketServer.GetLastError())
                        {
                            // If an error has been found.
                            if (exception != null)
                            {
                                throw exception;
                            }
                        }
                    }

                    _isListening = true;
                }
            }
            catch (Exception ex)
            {
                _isListening = false;

                // Dispose of the server if error.
                if (_socketServer != null)
                {
                    _socketServer.Dispose();
                    _socketServer = null;
                }

                // If an event application name exists for logging.
                if (!String.IsNullOrEmpty(Helper.EventApplicationName))
                {
                    // Log the error.
                    LogHandler.WriteTypeMessage(ex.Message,
                                                MethodInfo.GetCurrentMethod(), Helper.EventApplicationName);
                }
            }
        }