Advtools.AdvInterceptor.AdvWebServer.Start C# (CSharp) Метод

Start() публичный Метод

public Start ( ) : void
Результат void
        public void Start()
        {
            //HttpServer.Logging.LogFactory.Assign(new HttpServer.Logging.ConsoleLogFactory(null));

            // TODO: more than one Interception can be configured with the same port and IP

            foreach(var interception in state_.Config.Interceptions)
            {
                IPAddress ip = GetIp(interception.IPv4);
                if(ip == null)
                {
                    state_.Logger.Error("Invalid IPv4 address: {0}", interception.IPv4);
                    continue;
                }

                state_.Logger.Information("Intercept {0} {2} {3}:{1}", interception.Protocol, interception.Port, interception.Name, ip);

                try
                {
                    HttpListener listener = interception.Protocol == Protocol.Https ?
                        HttpListener.Create(ip, interception.Port, certificatesMgr_.GetCertificate(interception.Name)) :
                        HttpListener.Create(ip, interception.Port);
                    listener.RequestReceived += OnRequest;
                    listener.Start(state_.Config.Web.WebBacklog);
                    listeners_.Add(listener);
                }
                catch(System.Net.Sockets.SocketException e)
                {
                    state_.Logger.Exception(e, "Error setting up listener on port {0}", interception.Port);
                }
            }
        }

Usage Example

Пример #1
0
        private static void StartServers(Options options)
        {
            Configuration config = null;

            if (options.DefaultConfig)
            {
                config = Configuration.Default;
                config.Save(options.ConfigFile);
            }
            else
            {
                config = Configuration.Load(options.ConfigFile);
            }

            State state = new State(config, options.Level);

            AdvDnsServer dns = new AdvDnsServer(state, options.Intercept);

            dns.Start();

            if (options.Intercept)
            {
                AdvWebServer web = new AdvWebServer(state);
                web.Start();
            }
        }
All Usage Examples Of Advtools.AdvInterceptor.AdvWebServer::Start