Bloom.Api.ServerBase.StartListening C# (CSharp) Method

StartListening() public method

public StartListening ( ) : void
return void
        public virtual void StartListening()
        {
            const int kStartingPort = 8089;
            const int kNumberOfPortsToTry = 10;
            bool success = false;
            const int kNumberOfPortsWeNeed = 2;//one for http, one for peakLevel webSocket

            //Note: while this will find a port for the http, it does not actually know if the accompanying
            //ports are available. It just assume they are.
            //So while it's an improvement, it's not yet as solid as we would like it
            //to be.  The ultimate solution is to run the websocket and http on the same port.
            //This could be done using this proxy thing that internally routes to different ports:
            // https://github.com/lifeemotions/websocketproxy
            // Another thing to check on is https://github.com/bryceg/Owin.WebSocket/pull/20 which
            // would give us an owin-compliant version of the fleck websocket server, and we could
            // switch to using an owin-compliant http server like NancyFx.
            for (var i=0; !success && i < kNumberOfPortsToTry; i++)
            {
                ServerBase.portForHttp = kStartingPort + (i*kNumberOfPortsWeNeed);
                success = AttemptToOpenPort();
            }

            if(!success)
            {

                SIL.Reporting.ErrorReport.NotifyUserOfProblem(GetServerStartFailureMessage());
                Logger.WriteEvent("Error: Could not start up internal HTTP Server");
                Analytics.ReportException(new ApplicationException("Could not start server."));
                Application.Exit();
            }

            Logger.WriteEvent("Server will use " + ServerUrlEndingInSlash);
            _listenerThread.Start();

            for (var i = 0; i < Math.Max(Environment.ProcessorCount, 2); i++)
            {
                SpinUpAWorker();
            }

            VerifyWeAreNowListening();
        }