Esempio n. 1
0
        static void Main(string[] args)
        {
            SocketServer.SocketServer server = new SocketServer.SocketServer();
            bool bl = server.start();

            if (!bl)
            {
                Console.ReadKey();
                return;
            }

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");
            char c;

            while ((c = Console.ReadKey().KeyChar) != 'q')
            {
                if (c == 's')
                {
                    testSend();
                }
                if (c == 'a')
                {
                    senginfo();
                }
                Console.WriteLine();
                continue;
            }

            server.stop();
            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
Esempio n. 2
0
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            try
            {
                int serverPort = SocketServer.SocketServer.DEFAULT_SOCK_SERVER_PORT;
                int sendBuffer = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int receiveBuffer = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int managementServerPort = SocketServer.SocketServer.DEFAULT_MANAGEMENT_PORT;

                //Numan Hanif: in case of compact serilization plus DS Provider in same dll we search in deploy dir brute forcely
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Common.Util.AssemblyResolveEventHandler.DeployAssemblyHandler);
                try
                {

                    string configPort = ConfigurationSettings.AppSettings["NCacheServer.Port"];

                    if (configPort.Length > 0)
                    {
                        serverPort = Convert.ToInt32(configPort);
                    }

                    string managePort = ConfigurationSettings.AppSettings["NCacheServer.ManagementPort"];

                    if (managePort.Length > 0)
                    {
                        managementServerPort = Convert.ToInt32(managePort);
                    }

                    string configSendBuffer = ConfigurationSettings.AppSettings["NCacheServer.SendBufferSize"];

                    if (configSendBuffer.Length > 0)
                    {
                        sendBuffer = Convert.ToInt32(configSendBuffer);
                    }

                    string configReceiveBuffer = ConfigurationSettings.AppSettings["NCacheServer.ReceiveBufferSize"];

                    if (configReceiveBuffer.Length > 0)
                    {
                        receiveBuffer = Convert.ToInt32(configReceiveBuffer);
                    }
                }
                catch (Exception)
                {
                }

                _nchost = new CacheHost();

                _socketServer = new SocketServer.SocketServer(serverPort, sendBuffer, receiveBuffer);

                try
                {
                    int period = -1;
                    string intervalString = ConfigurationSettings.AppSettings["GCCollectInterval"];
                    if (intervalString.Length > 0)
                    {
                        period = Convert.ToInt32(intervalString);
                    }
                    _socketServer.StartGCTimer(5, period);
                }
                catch (Exception)
                { }

                IPAddress clusterIp = null;
                if (_clusterIp != null && _clusterIp != string.Empty)
                {
                    try
                    {
                        clusterIp = IPAddress.Parse(_clusterIp);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Invalid BindToIP address specified");
                    }
                }

                ValidateMapAddress("NCacheServer.MgmtEndPoint");
                ValidateMapAddress("NCacheServer.ServerEndPoint");

                _nchost.RegisterMonitorServer();
                //muds:
                //start the socket server separately.
                //Start the NCache Management socket server seperately
                _managementSocketServer = new SocketServer.SocketServer(managementServerPort, sendBuffer, receiveBuffer);

                _managementSocketServer.Start(clusterIp, Alachisoft.NCache.Common.Logger.LoggerNames.CacheManagementSocketServer, "NManagement Service", CommandManagerType.NCacheManagement);
                _socketServer.Start(clusterIp, Alachisoft.NCache.Common.Logger.LoggerNames.SocketServerLogs, "NCache Service", CommandManagerType.NCacheClient);

                CacheServer.SocketServerPort = managementServerPort;
                _nchost.CacheServer.SynchronizeClientConfig();
                _nchost.CacheServer.ClusterIP = _clusterIp;
                _nchost.CacheServer.Renderer = _socketServer;
                Alachisoft.NCache.SocketServer.CacheProvider.Provider = _nchost.CacheServer;
            }
            catch (Exception ex)
            {
                AppUtil.LogEvent(_cacheserver, ex.ToString(), EventLogEntryType.Error, EventCategories.Error, EventID.GeneralError);
                throw ex;
            }
        }
Esempio n. 3
0
 protected void Application_Start(object sender, EventArgs e)
 {
     SocketServer.SocketServer server = new SocketServer.SocketServer();
     bool bl = server.start();
 }
Esempio n. 4
0
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        public void OnStart(string[] args)
        {
            try
            {
                int serverPort           = SocketServer.SocketServer.DEFAULT_SOCK_SERVER_PORT;
                int sendBuffer           = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int receiveBuffer        = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int managementServerPort = SocketServer.SocketServer.DEFAULT_MANAGEMENT_PORT;

                //Numan Hanif: in case of compact serilization plus DS Provider in same dll we search in deploy dir brute forcely
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Common.Util.AssemblyResolveEventHandler.DeployAssemblyHandler);
                try
                {
                    serverPort           = ServiceConfiguration.Port;
                    managementServerPort = ServiceConfiguration.ManagementPort;

                    if (ServiceConfiguration.SendBufferSize > 0)
                    {
                        sendBuffer = ServiceConfiguration.SendBufferSize;
                    }

                    if (ServiceConfiguration.ReceiveBufferSize > 0)
                    {
                        receiveBuffer = ServiceConfiguration.ReceiveBufferSize;
                    }
                }
                catch (Exception)
                {
                }


                //Thread.Sleep(15000);
                _socketServer = new SocketServer.SocketServer(serverPort, sendBuffer, receiveBuffer);

                //#if VS2005
                //                _nchost.StartHosting(TCP_CHANNEL_NAME, HTTP_CHANNEL_NAME,IPC_CHANNEL_NAME);

                //#else
                IPAddress clusterIp      = null;
                IPAddress clientServerIp = null;
#if JAVA
                if (_clusterIp != null && _clusterIp != string.Empty)
                {
                    try
                    {
                        clusterIp = IPAddress.Parse(_clusterIp);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Invalid BindToClusterIP address specified");
                    }
                }
#else
                clusterIp = ServiceConfiguration.BindToClusterIP;
#endif
#if JAVA
                if (_clientServerIp != null && _clientServerIp != string.Empty)
                {
                    try
                    {
                        clientServerIp = IPAddress.Parse(_clientServerIp);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Invalid BindToClientServerIP address specified");
                    }
                }
#else
                clientServerIp = ServiceConfiguration.BindToClientServerIP;
#endif

                //if (clusterIp == null)
                //{

                //    _nchost.StartHosting(TCP_CHANNEL_NAME, HTTP_CHANNEL_NAME);
                //}
                //else
                //{
                //    _nchost.StartHosting(TCP_CHANNEL_NAME, HTTP_CHANNEL_NAME, _clusterIp);
                //}

                //_nchost.RegisterMonitorServer();
                ////muds:
                ////start the socket server separately.
                //_socketServer.Start(clientServerIp);
                //CacheServer.SocketServerPort = serverPort;
                //_nchost.CacheServer.SynchronizeClientConfig();

                //_nchost.CacheServer.Renderer = _socketServer;
                //Alachisoft.NCache.SocketServer.CacheProvider.Provider = _nchost.CacheServer;

                //_nchost.RegisterMonitorServer();
                //muds:
                //start the socket server separately.
                // _socketServer.Start(clientServerIp, Alachisoft.NCache.Common.Logger.LoggerNames.SocketServerLogs, "NCache Service", CommandManagerType.NCacheClient);
                //Start the NCache Management socket server seperately
                //File.WriteAllText(@"C:\service.txt", "Before M");
                _managementSocketServer = new SocketServer.SocketServer(managementServerPort, sendBuffer, receiveBuffer);
#if JAVA
                _managementSocketServer.Start(clusterIp, Alachisoft.NCache.Common.Logger.LoggerNames.CacheManagementSocketServer, "TGManagement Service", CommandManagerType.NCacheManagement);
                _socketServer.Start(clientServerIp, Alachisoft.NCache.Common.Logger.LoggerNames.SocketServerLogs, "TayzGrid Service", CommandManagerType.NCacheClient);
#else
                _managementSocketServer.Start(clusterIp, Alachisoft.NCache.Common.Logger.LoggerNames.CacheManagementSocketServer, "NManagement Service", CommandManagerType.NCacheManagement, ConnectionManagerType.Management);
                _socketServer.Start(clientServerIp, Alachisoft.NCache.Common.Logger.LoggerNames.SocketServerLogs, "NCache Service", CommandManagerType.NCacheService, ConnectionManagerType.ServiceClient);
#endif
                CacheServer.SocketServerPort = managementServerPort;
                _nchost.CacheServer.SynchronizeClientConfig();
                _nchost.CacheServer.ClusterIP = clusterIp.ToString();
                _nchost.CacheServer.Renderer  = _socketServer;
                _nchost.CacheServer.Renderer.ManagementIPAddress      = clusterIp.ToString();
                _nchost.CacheServer.Renderer.ManagementPort           = managementServerPort;
                Alachisoft.NCache.SocketServer.CacheProvider.Provider = _nchost.CacheServer;

                if (Licensing.LicenseManager.LicenseMode(null) == Licensing.LicenseManager.LicenseType.InEvaluation)
                {
                    _cacheServerEvalTask          = new System.Timers.Timer();
                    _cacheServerEvalTask.Interval = 1000 * 60 * 60 * 12;// 12 hour interval.
                    _cacheServerEvalTask.Elapsed += new ElapsedEventHandler(CacheServer.NotifyEvalLicense);
                    _cacheServerEvalTask.Enabled  = true;

                    ThreadPool.QueueUserWorkItem(new WaitCallback(CacheServer.NotifyEvalLicense));

                    _evalWarningTask          = new System.Timers.Timer();
                    _evalWarningTask.Interval = 1000 * 60 * 60 * 12;// 12 hour interval.
                    _evalWarningTask.Elapsed += new ElapsedEventHandler(NotifyEvalLicense);
                    _evalWarningTask.Enabled  = true;
                    NotifyEvalLicense(null, null);
                }
                // if reactivation exists than generate event after every day
                if (Licensing.LicenseManager.Reactivate)
                {
                    _reactWarningTask          = new System.Timers.Timer();
                    _reactWarningTask.Interval = ServiceConfiguration.LicenseCheckInterval;//1 day
                    _reactWarningTask.Elapsed += new ElapsedEventHandler(NotifyReactivateLicense);
                    _reactWarningTask.Enabled  = true;
                    NotifyReactivateLicense(null, null);
                }
                // Load configuration is separate thread to boost performance
                AssignMananagementPorts();
                AssignServerstoRunningCaches();
                ThreadPool.QueueUserWorkItem(new WaitCallback(GetRunningCaches));
                // ThreadPool.QueueUserWorkItem(new WaitCallback(AutoStartCaches));

                //AutoStartCaches(new object());
                //#endif
                //
                StartPerfmonLogging();
            }
            catch (Exception ex)
            {
                AppUtil.LogEvent(_cacheserver, ex.ToString(), EventLogEntryType.Error, EventCategories.Error, EventID.GeneralError);
                throw ex;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            try
            {
                int serverPort           = SocketServer.SocketServer.DEFAULT_SOCK_SERVER_PORT;
                int sendBuffer           = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int receiveBuffer        = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int managementServerPort = SocketServer.SocketServer.DEFAULT_MANAGEMENT_PORT;

                //in case of compact serilization plus DS Provider in same dll we search in deploy dir brute forcely
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Common.Util.AssemblyResolveEventHandler.DeployAssemblyHandler);
                try
                {
                    serverPort           = ServiceConfiguration.Port;
                    managementServerPort = ServiceConfiguration.ManagementPort;

                    if (ServiceConfiguration.SendBufferSize > 0)
                    {
                        sendBuffer = ServiceConfiguration.SendBufferSize;
                    }

                    if (ServiceConfiguration.ReceiveBufferSize > 0)
                    {
                        receiveBuffer = ServiceConfiguration.ReceiveBufferSize;
                    }
                }
                catch (Exception)
                {
                }

                _socketServer = new SocketServer.SocketServer(serverPort, sendBuffer, receiveBuffer);

                try
                {
                    int    period         = -1;
                    string intervalString = ConfigurationSettings.AppSettings["GCCollectInterval"];
                    if (intervalString.Length > 0)
                    {
                        period = Convert.ToInt32(intervalString);
                    }
                    _socketServer.StartGCTimer(5, period);
                }
                catch (Exception)
                { }


                IPAddress clusterIp = null;
                clusterIp = ServiceConfiguration.BindToIP;

                ValidateMapAddress("NCacheServer.MgmtEndPoint");
                ValidateMapAddress("NCacheServer.ServerEndPoint");
                //start the socket server separately.
                //Start the NCache Management socket server seperately
                _managementSocketServer = new SocketServer.SocketServer(managementServerPort, sendBuffer, receiveBuffer);

                _managementSocketServer.Start(clusterIp, Common.Logger.LoggerNames.CacheManagementSocketServer, "NManagement Service", CommandManagerType.NCacheManagement, ConnectionManagerType.Management);
                _socketServer.Start(clusterIp, Common.Logger.LoggerNames.SocketServerLogs, "NCache Service", CommandManagerType.NCacheService, ConnectionManagerType.ServiceClient);

                CacheServer.SocketServerPort = managementServerPort;
                _nchost.CacheServer.SynchronizeClientConfig();
                _nchost.CacheServer.ClusterIP = clusterIp.ToString();
                _nchost.CacheServer.Renderer  = _socketServer;
                _nchost.CacheServer.Renderer.ManagementIPAddress = clusterIp.ToString();
                _nchost.CacheServer.Renderer.ManagementPort      = managementServerPort;
                CacheProvider.Provider = _nchost.CacheServer;

                // Load configuration is separate thread to boost performance
                ThreadPool.QueueUserWorkItem(new WaitCallback(GetRunningCaches));
            }
            catch (Exception ex)
            {
                AppUtil.LogEvent(_cacheserver, ex.ToString(), EventLogEntryType.Error, EventCategories.Error, EventID.GeneralError);
                throw ex;
            }
        }
        public static void StartCacheHost()
        {
            cacheName = cacheName.ToLower();
            string    _clientServerIp = string.Empty;
            IPAddress clusterIp       = null;
            IPAddress clientServerIp  = null;

            try
            {
                Alachisoft.NCache.Common.Util.AssemblyResolveEventHandler.CacheName = cacheName;
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                AppDomain.CurrentDomain.AssemblyResolve    += new ResolveEventHandler(Alachisoft.NCache.Common.Util.AssemblyResolveEventHandler.DeployAssemblyHandler);
                int sendBuffer    = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int receiveBuffer = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                if (ServiceConfiguration.SendBufferSize > 0)
                {
                    sendBuffer = ServiceConfiguration.SendBufferSize;
                }
                if (ServiceConfiguration.ReceiveBufferSize > 0)
                {
                    receiveBuffer = ServiceConfiguration.ReceiveBufferSize;
                }
                _nchost       = new Alachisoft.NCache.Management.CacheHost();
                _socketServer = new SocketServer.SocketServer(ServiceConfiguration.Port, sendBuffer, receiveBuffer);
                _nchost.HostServer.Renderer = _socketServer;
#if !NETCORE && !NETCOREAPP2_0
                try
                {
                    string        serviceEXE1 = Path.Combine(AppUtil.InstallDir, "bin");
                    string        serviceEXE2 = Path.Combine(serviceEXE1, "service");
                    string        serviceEXE3 = Path.Combine(serviceEXE2, "Alachisoft.NCache.Service.exe");
                    Configuration config      = ConfigurationManager.OpenExeConfiguration(serviceEXE3);
                }
                catch (Exception ex) { return; }
#else
                try
                {
                    string        serviceEXE1 = Path.Combine(AppUtil.InstallDir, "bin");
                    string        serviceEXE2 = Path.Combine(serviceEXE1, "service");
                    string        serviceEXE3 = Path.Combine(serviceEXE2, "Alachisoft.NCache.Daemon.dll");
                    Configuration config      = ConfigurationManager.OpenExeConfiguration(serviceEXE3);
                }
                catch (Exception ex) { return; }
#endif

                try
                {
                    clusterIp = ServiceConfiguration.BindToIP;
                }
                catch (Exception)
                {
                    ErrorCode = 5;
                    throw new Exception("Invalid BindToClusterIP address specified.");
                }


                try
                {
                    clientServerIp = ServiceConfiguration.BindToIP;
                }
                catch (Exception)
                {
                    ErrorCode = 6;
                    throw new Exception("Invalid BindToClientServerIP address specified");
                }

                try
                {
                    if (!Helper.isPortFree(managementPort, clusterIp))
                    {
                        ErrorCode = 8;
                        throw new Exception("Management listener can not be started. The port might already be in use");
                    }
                }
                catch (Exception ex)
                {
                    if (ex.ToString().Contains("Specified argument was out of the range of valid values"))
                    {
                        ErrorCode = 10;
                        throw new Exception("The port is outside the range of valid values for Management.");
                    }
                    else
                    {
                        throw;
                    }
                }


                _socketServer.CacheName = cacheName;
                Alachisoft.NCache.SocketServer.CacheProvider.Provider = _nchost.HostServer;
                _managementSocketServer = new SocketServer.SocketServer(managementPort, sendBuffer, receiveBuffer);


                _managementSocketServer.Start(clusterIp, Alachisoft.NCache.Common.Logger.LoggerNames.CacheManagementSocketServer, "NManagement", CommandManagerType.NCacheHostManagement, ConnectionManagerType.Management);
                _socketServer.Start(clientServerIp, Alachisoft.NCache.Common.Logger.LoggerNames.SocketServerLogs, "Cache Host", CommandManagerType.NCacheClient, ConnectionManagerType.HostClient);

                CacheServer.SocketServerPort  = managementPort;
                CacheServer.ConnectionManager = SocketServer.SocketServer.HostClientConnectionManager;
                _nchost.HostServer.SynchronizeClientConfig();
                _nchost.HostServer.ClusterIP = clusterIp.ToString();
                _nchost.HostServer.Renderer.ManagementIPAddress = clusterIp.ToString();
                OnCacheStopped cacheStoppedDelegate = new OnCacheStopped(onCacheStopped);
                _nchost.HostServer.RegisterCacheStopCallback(cacheStoppedDelegate);

                //for debugging purposes, comment this line
                _nchost.HostServer.InitiateCacheHostStopThread();
                AppUtil.LogEvent(_applicationName, "Cache [ " + cacheName + " ] separate process is started successfully.", EventLogEntryType.Information, EventCategories.Information, EventID.GeneralInformation);
            }
            catch (Exception e)
            {
                throwError(e.ToString(), false);
            }

            try
            {
                // Start the watcher to check if service configuration file gets changed.
                // For hot applicable

                FileSystemWatcher configWatcher = new FileSystemWatcher();
                string            path          = Path.Combine(AppUtil.InstallDir, "bin");
                configWatcher.Path                = Path.Combine(path, "service");
                configWatcher.Filter              = "*.config";
                configWatcher.NotifyFilter        = NotifyFilters.LastWrite;
                configWatcher.Changed            += ServiceConfigChanged;
                configWatcher.EnableRaisingEvents = true;
            }
            catch (Exception)
            {
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Set things in motion so your service can do its work.
        /// </summary>
        protected override void OnStart(string[] args)
        {
            try
            {
                int serverPort           = SocketServer.SocketServer.DEFAULT_SOCK_SERVER_PORT;
                int sendBuffer           = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int receiveBuffer        = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int managementServerPort = SocketServer.SocketServer.DEFAULT_MANAGEMENT_PORT;

                //Numan Hanif: in case of compact serilization plus DS Provider in same dll we search in deploy dir brute forcely
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Common.Util.AssemblyResolveEventHandler.DeployAssemblyHandler);
                try
                {
                    string configPort = ConfigurationSettings.AppSettings["NCacheServer.Port"];

                    if (configPort.Length > 0)
                    {
                        serverPort = Convert.ToInt32(configPort);
                    }

                    string managePort = ConfigurationSettings.AppSettings["NCacheServer.ManagementPort"];

                    if (managePort.Length > 0)
                    {
                        managementServerPort = Convert.ToInt32(managePort);
                    }

                    string configSendBuffer = ConfigurationSettings.AppSettings["NCacheServer.SendBufferSize"];

                    if (configSendBuffer.Length > 0)
                    {
                        sendBuffer = Convert.ToInt32(configSendBuffer);
                    }

                    string configReceiveBuffer = ConfigurationSettings.AppSettings["NCacheServer.ReceiveBufferSize"];

                    if (configReceiveBuffer.Length > 0)
                    {
                        receiveBuffer = Convert.ToInt32(configReceiveBuffer);
                    }
                }
                catch (Exception)
                {
                }

                _nchost = new CacheHost();

                _socketServer = new SocketServer.SocketServer(serverPort, sendBuffer, receiveBuffer);

                try
                {
                    int    period         = -1;
                    string intervalString = ConfigurationSettings.AppSettings["GCCollectInterval"];
                    if (intervalString.Length > 0)
                    {
                        period = Convert.ToInt32(intervalString);
                    }
                    _socketServer.StartGCTimer(5, period);
                }
                catch (Exception)
                { }


                IPAddress clusterIp = null;
                if (_clusterIp != null && _clusterIp != string.Empty)
                {
                    try
                    {
                        clusterIp = IPAddress.Parse(_clusterIp);
                    }
                    catch (Exception)
                    {
                        throw new Exception("Invalid BindToIP address specified");
                    }
                }

                ValidateMapAddress("NCacheServer.MgmtEndPoint");
                ValidateMapAddress("NCacheServer.ServerEndPoint");



                _nchost.RegisterMonitorServer();
                //muds:
                //start the socket server separately.
                //Start the NCache Management socket server seperately
                _managementSocketServer = new SocketServer.SocketServer(managementServerPort, sendBuffer, receiveBuffer);

                _managementSocketServer.Start(clusterIp, Alachisoft.NCache.Common.Logger.LoggerNames.CacheManagementSocketServer, "NManagement Service", CommandManagerType.NCacheManagement);
                _socketServer.Start(clusterIp, Alachisoft.NCache.Common.Logger.LoggerNames.SocketServerLogs, "NCache Service", CommandManagerType.NCacheClient);

                CacheServer.SocketServerPort = managementServerPort;
                _nchost.CacheServer.SynchronizeClientConfig();
                _nchost.CacheServer.ClusterIP = _clusterIp;
                _nchost.CacheServer.Renderer  = _socketServer;
                Alachisoft.NCache.SocketServer.CacheProvider.Provider = _nchost.CacheServer;
            }
            catch (Exception ex)
            {
                AppUtil.LogEvent(_cacheserver, ex.ToString(), EventLogEntryType.Error, EventCategories.Error, EventID.GeneralError);
                throw ex;
            }
        }
Esempio n. 8
0
        private static void StartCacheHost()
        {
            string    _clientServerIp = string.Empty;
            IPAddress clusterIp       = null;
            IPAddress clientServerIp  = null;

            try
            {
                AssemblyResolveEventHandler.CacheName       = cacheName;
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                AppDomain.CurrentDomain.AssemblyResolve    += new ResolveEventHandler(Alachisoft.NCache.Common.Util.AssemblyResolveEventHandler.DeployAssemblyHandler);
                int sendBuffer    = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;
                int receiveBuffer = SocketServer.SocketServer.DEFAULT_SOCK_BUFFER_SIZE;


                if (ServiceConfiguration.SendBufferSize > 0)
                {
                    sendBuffer = ServiceConfiguration.SendBufferSize;
                }

                if (ServiceConfiguration.ReceiveBufferSize > 0)
                {
                    receiveBuffer = ServiceConfiguration.ReceiveBufferSize;
                }


                _nchost       = new Management.CacheHost();
                _socketServer = new SocketServer.SocketServer(ServiceConfiguration.Port, sendBuffer, receiveBuffer);
                string        part1      = Path.Combine(AppUtil.InstallDir, "bin");
                string        part2      = Path.Combine(part1, "service");
                string        serviceEXE = Path.Combine(part2, "Alachisoft.NCache.Service.exe");
                Configuration config     = ConfigurationManager.OpenExeConfiguration(serviceEXE);

                try
                {
                    clusterIp = ServiceConfiguration.BindToIP;
                }
                catch (Exception)
                {
                    ErrorCode = 5;
                    throw new Exception("Invalid BindToClusterIP address specified.");
                }


                try
                {
                    clientServerIp = ServiceConfiguration.BindToIP;
                }
                catch (Exception)
                {
                    ErrorCode = 6;
                    throw new Exception("Invalid BindToClientServerIP address specified");
                }

                try
                {
                    if (!Helper.isPortFree(managementPort, clusterIp))
                    {
                        ErrorCode = 8;
                        throw new Exception("Management listener can not be started. The port might already be in use");
                    }
                }
                catch (Exception ex)
                {
                    if (ex.ToString().Contains("Specified argument was out of the range of valid values"))
                    {
                        ErrorCode = 10;
                        throw new Exception("The port is outside the range of valid values for Management.");
                    }
                    else
                    {
                        throw;
                    }
                }

                _socketServer.CacheName = cacheName;
                CacheProvider.Provider  = _nchost.HostServer;
                _managementSocketServer = new SocketServer.SocketServer(managementPort, sendBuffer, receiveBuffer);


                _managementSocketServer.Start(clusterIp, Common.Logger.LoggerNames.CacheManagementSocketServer, "NManagement", CommandManagerType.NCacheHostManagement, ConnectionManagerType.Management);
                _socketServer.Start(clientServerIp, Common.Logger.LoggerNames.SocketServerLogs, "Cache Host", CommandManagerType.NCacheClient, ConnectionManagerType.HostClient);


                CacheServer.SocketServerPort  = managementPort;
                CacheServer.ConnectionManager = _socketServer.HostClientConnectionManager;

                _nchost.HostServer.SynchronizeClientConfig();
                _nchost.HostServer.ClusterIP = clusterIp.ToString();
                _nchost.HostServer.Renderer  = _socketServer;
                _nchost.HostServer.Renderer.ManagementIPAddress = clusterIp.ToString();
                OnCacheStopped cacheStoppedDelegate = new OnCacheStopped(onCacheStopped);
                _nchost.HostServer.RegisterCacheStopCallback(cacheStoppedDelegate);

                _nchost.HostServer.InitiateCacheHostStopThread();
                AppUtil.LogEvent(_applicationName, "Cache [ " + cacheName + " ] separate process is started successfully.", EventLogEntryType.Information, EventCategories.Information, EventID.GeneralInformation);
            }
            catch (Exception e)
            {
                throwError(e.ToString(), false);
            }
        }