Ejemplo n.º 1
0
        private void StartHttpServer()
        {
            try
            {
                int http_port = TrinityConfig.HttpPort;
                if (http_port <= UInt16.MinValue || http_port > UInt16.MaxValue)
                {
                    return;
                }

                List <string> endpoints = new List <string> {
                    string.Format(CultureInfo.InvariantCulture, "http://+:{0}/", http_port)
                };
                m_HttpServer = new TrinityHttpServer(_HttpHandler, endpoints);

                if (RunningMode == Trinity.RunningMode.Server)
                {
                    m_HttpServer.SetInstanceList(TrinityConfig.Servers);
                }
                else if (RunningMode == Trinity.RunningMode.Proxy)
                {
                    m_HttpServer.SetInstanceList(TrinityConfig.Proxies);
                }

                m_HttpServer.Listen();
                Log.WriteLine(LogLevel.Info, "HTTP server listening on port {0}", http_port);
            }
            catch
            {
                Log.WriteLine(LogLevel.Error, "Failed to start HTTP server. HTTP endpoints are disabled.");
            }
        }
Ejemplo n.º 2
0
        private void StopHttpServer()
        {
            if (m_HttpServer == null) return;

            try
            {
                m_HttpServer.Dispose();
                m_HttpServer = null;
                Log.WriteLine(LogLevel.Info, "HTTP server stopped");
            }
            catch
            {
                Log.WriteLine(LogLevel.Error, "Failed to stop HTTP server.");
            }
        }