不具合修正のためにしぶしぶ継承
Наследование: TrotiNet.TcpServer
Пример #1
0
        /// <summary>
        /// 指定ポートで Listening を開始する。
        /// Shutdown() を呼び出さずに2回目の Startup() を呼び出した場合、InvalidOperationException が発生する。
        /// </summary>
        /// <param name="listeningPort">Listeningするポート。</param>
        /// <param name="useIpV6">falseの場合、127.0.0.1で待ち受ける。trueの場合、::1で待ち受ける。既定false。</param>
        /// <param name="isSetProxyInProcess">trueの場合、プロセス内IEプロキシの設定を実施し、HTTP通信をNekoxyに向ける。既定true。</param>
        public static void Startup(int listeningPort, bool useIpV6 = false, bool isSetProxyInProcess = true)
        {
            if (server != null)
            {
                throw new InvalidOperationException("Calling Startup() twice without calling Shutdown() is not permitted.");
            }

            TransparentProxyLogic.AfterSessionComplete     += InvokeAfterSessionComplete;
            TransparentProxyLogic.AfterReadRequestHeaders  += InvokeAfterReadRequestHeaders;
            TransparentProxyLogic.AfterReadResponseHeaders += InvokeAfterReadResponseHeaders;
            ListeningPort = listeningPort;
            try
            {
                if (isSetProxyInProcess)
                {
                    WinInetUtil.SetProxyInProcessForNekoxy(listeningPort);
                }

                server = new NekoxyTcpServer(listeningPort, useIpV6);
                server.Start(TransparentProxyLogic.CreateProxy);
                server.InitListenFinished.WaitOne();
                if (server.InitListenException != null)
                {
                    throw server.InitListenException;
                }
            }
            catch (Exception)
            {
                Shutdown();
                throw;
            }
        }
Пример #2
0
 /// <summary>
 /// Listening しているスレッドを終了し、ソケットを閉じる。
 /// </summary>
 public static void Shutdown()
 {
     TransparentProxyLogic.AfterSessionComplete     -= InvokeAfterSessionComplete;
     TransparentProxyLogic.AfterReadRequestHeaders  -= InvokeAfterReadRequestHeaders;
     TransparentProxyLogic.AfterReadResponseHeaders -= InvokeAfterReadResponseHeaders;
     server?.Shutdown();
     server = null;
 }
Пример #3
0
        /// <summary>
        /// 指定ポートで Listening を開始する。
        /// Shutdown() を呼び出さずに2回目の Startup() を呼び出した場合、InvalidOperationException が発生する。
        /// </summary>
        /// <param name="listeningPort">Listeningするポート。</param>
        /// <param name="useIpV6">falseの場合、127.0.0.1で待ち受ける。trueの場合、::1で待ち受ける。既定false。</param>
        /// <param name="isSetProxyInProcess">trueの場合、プロセス内IEプロキシの設定を実施し、HTTP通信をNekoxyに向ける。既定true。</param>
        public static void Startup(int listeningPort, bool useIpV6 = false, bool isSetProxyInProcess = true)
        {
            if (server != null) throw new InvalidOperationException("Calling Startup() twice without calling Shutdown() is not permitted.");

            TransparentProxyLogic.AfterSessionComplete += InvokeAfterSessionComplete;
            TransparentProxyLogic.AfterReadRequestHeaders += InvokeAfterReadRequestHeaders;
            TransparentProxyLogic.AfterReadResponseHeaders += InvokeAfterReadResponseHeaders;
            ListeningPort = listeningPort;
            try
            {
                if (isSetProxyInProcess)
                    WinInetUtil.SetProxyInProcessForNekoxy(listeningPort);

                server = new NekoxyTcpServer(listeningPort, useIpV6);
                server.Start(TransparentProxyLogic.CreateProxy);
                server.InitListenFinished.WaitOne();
                if (server.InitListenException != null) throw server.InitListenException;
            }
            catch (Exception)
            {
                Shutdown();
                throw;
            }
        }
Пример #4
0
 /// <summary>
 /// Listening しているスレッドを終了し、ソケットを閉じる。
 /// </summary>
 public static void Shutdown()
 {
     TransparentProxyLogic.AfterSessionComplete -= InvokeAfterSessionComplete;
     TransparentProxyLogic.AfterReadRequestHeaders -= InvokeAfterReadRequestHeaders;
     TransparentProxyLogic.AfterReadResponseHeaders -= InvokeAfterReadResponseHeaders;
     server?.Shutdown();
     server = null;
 }