private void StartHTTP() { m_log.InfoFormat( "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port); try { //m_httpListener = new HttpListener(); NotSocketErrors = 0; if (!m_ssl) { //m_httpListener.Prefixes.Add("http://+:" + m_port + "/"); //m_httpListener.Prefixes.Add("http://10.1.1.5:" + m_port + "/"); m_httpListener2 = CoolHTTPListener.Create(m_listenIPAddress, (int)m_port); m_httpListener2.ExceptionThrown += httpServerException; m_httpListener2.LogWriter = httpserverlog; // Uncomment this line in addition to those in HttpServerLogWriter // if you want more detailed trace information from the HttpServer //m_httpListener2.UseTraceLogs = true; //m_httpListener2.DisconnectHandler = httpServerDisconnectMonitor; } else { //m_httpListener.Prefixes.Add("https://+:" + (m_sslport) + "/"); //m_httpListener.Prefixes.Add("http://+:" + m_port + "/"); m_httpListener2 = CoolHTTPListener.Create(IPAddress.Any, (int)m_port, m_cert); m_httpListener2.ExceptionThrown += httpServerException; m_httpListener2.LogWriter = httpserverlog; } m_httpListener2.RequestReceived += OnRequest; //m_httpListener.Start(); m_httpListener2.Start(64); // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000); m_PollServiceManager.Start(); HTTPDRunning = true; //HttpListenerContext context; //while (true) //{ // context = m_httpListener.GetContext(); // ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(HandleRequest), context); // } } catch (Exception e) { m_log.Error("[BASE HTTP SERVER]: Error - " + e.Message); m_log.Error("[BASE HTTP SERVER]: Tip: Do you have permission to listen on port " + m_port + ", " + m_sslport + "?"); // We want this exception to halt the entire server since in current configurations we aren't too // useful without inbound HTTP. throw e; } m_requestsProcessedStat = new Stat( "HTTPRequestsServed", "Number of inbound HTTP requests processed", "", "requests", "httpserver", Port.ToString(), StatType.Pull, MeasuresOfInterest.AverageChangeOverTime, stat => stat.Value = RequestNumber, StatVerbosity.Debug); StatsManager.RegisterStat(m_requestsProcessedStat); }
private void StartHTTP() { m_log.InfoFormat( "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port); try { //m_httpListener = new HttpListener(); NotSocketErrors = 0; if (!m_ssl) { //m_httpListener.Prefixes.Add("http://+:" + m_port + "/"); //m_httpListener.Prefixes.Add("http://10.1.1.5:" + m_port + "/"); m_httpListener2 = CoolHTTPListener.Create(m_listenIPAddress, (int)m_port); m_httpListener2.ExceptionThrown += httpServerException; m_httpListener2.LogWriter = httpserverlog; // Uncomment this line in addition to those in HttpServerLogWriter // if you want more detailed trace information from the HttpServer //m_httpListener2.UseTraceLogs = true; //m_httpListener2.DisconnectHandler = httpServerDisconnectMonitor; } else { //m_httpListener.Prefixes.Add("https://+:" + (m_sslport) + "/"); //m_httpListener.Prefixes.Add("http://+:" + m_port + "/"); System.Security.Cryptography.X509Certificates.X509Certificate2 cert = new System.Security.Cryptography.X509Certificates.X509Certificate2("SineWaveCert.pfx", "123"); m_httpListener2 = CoolHTTPListener.Create(IPAddress.Any, (int)m_port, m_cert); m_httpListener2.ExceptionThrown += httpServerException; m_httpListener2.LogWriter = httpserverlog; } m_httpListener2.RequestReceived += OnRequest; //m_httpListener.Start(); m_httpListener2.Start(64); // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000); m_PollServiceManager.Start(); HTTPDRunning = true; //HttpListenerContext context; //while (true) //{ // context = m_httpListener.GetContext(); // ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(HandleRequest), context); // } } catch (Exception e) { m_log.Error("[BASE HTTP SERVER]: Error - " + e.Message); m_log.Error("[BASE HTTP SERVER]: Tip: Do you have permission to listen on port " + m_port + ", " + m_sslport + "?"); // We want this exception to halt the entire server since in current configurations we aren't too // useful without inbound HTTP. throw e; } }