コード例 #1
0
        public void IsListening_Aborted_ReturnsFalse()
        {
            var listener = new HttpListener();

            listener.Abort();
            Assert.False(listener.IsListening);

            listener.Abort();
            Assert.False(listener.IsListening);
        }
コード例 #2
0
        public void AbortTwice()
        {
            if (!CanOpenPort(port))
            {
                Assert.Ignore("port");
            }
            HttpListener listener = new HttpListener();

            listener.Prefixes.Add("http://localhost:" + port + "/hola/");
            listener.Start();
            listener.Abort();
            listener.Abort();
        }
コード例 #3
0
 public void Stop()
 {
     listener.Abort();
     Thread.Sleep(50);
     listener.Close();
     Log($"WebServer stopped listening to requests on: {url}");
 }
コード例 #4
0
 public void Abort()
 {
     if (_Listener != null)
     {
         _Listener.Abort();
     }
 }
コード例 #5
0
 /// <summary>
 /// Stop server and dispose all functions.
 /// Note: This currently doesn't kill the listener thread
 /// despite the cancellation token. This means that the app doesn't
 /// exit gracefully. I call thread.abort forcing an exception to terminate it.
 /// </summary>
 public void Stop()
 {
     cts.Cancel();
     _listener.Abort();     // try to forcefully shut down the listener
     cts.Dispose();
     _serverThread.Abort(); // PNE fires!
 }
コード例 #6
0
        public void StopProxy()
        {
            SetStatus("Stopping Proxy...");

            _mWaitForExit = false;

            try
            {
                _mHttpListener.Abort();
            }
            catch (Exception)
            {
            }

            try
            {
                _mHttpListener.Stop();
            }
            catch (Exception)
            {
            }

            if (!_mClosing)
            {
                _mForm.SetChromeConnectedText("Chrome: [Not Connected]");
                _mForm.SetUnityConnectedText("Unity: [Not Connected]");
            }

            AppendStatus("Proxy Stopped!");
        }
コード例 #7
0
        public void Stop()
        {
            AppLog.Info("停止angular容器.");

            _listener?.Abort();
            _serverThread?.Abort();
        }
コード例 #8
0
        private bool disposedValue = false;         // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                }
                _end = true;
                KeepWorking?.Set();

                _listener?.Abort();
                //_listener?.Dispose();
                _listener = null;

                KeepWorking.Dispose();
                KeepWorking = null;
                ListenerStopped?.Dispose();
                ListenerStopped = null;

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
コード例 #9
0
        public bool Stop()
        {
            if (httpServer != null && httpServer.IsListening)
            {
                try
                {
                    httpServer.Abort();
                }
                catch (ObjectDisposedException)
                {
                }
            }

            if (thread != null)
            {
                try
                {
                    thread.Abort();
                }
                catch { }
                thread = null;
            }


            return(true);
        }
コード例 #10
0
 public void Dispose()
 {
     _httpListener.Abort();
     ((IDisposable)_httpListener).Dispose();
     _tokenSource.Cancel();
     _tokenSource.Dispose();
 }
コード例 #11
0
ファイル: ServerCtl.cs プロジェクト: xxxxst/httpServer
 public void clear()
 {
     httpListener?.Abort();
     httpListener = null;
     thServer?.Abort();
     thServer = null;
 }
コード例 #12
0
 public override void Dispose()
 {
     base.Dispose();
     _listener.Close();
     _listener.Abort();
     Console.WriteLine("stop listening.bye...");
 }
コード例 #13
0
 public void Stop()
 {
     if (listener != null)
     {
         listener.Abort();
     }
 }
コード例 #14
0
        private static async Task ListenAsync(CancellationToken token)
        {
            using (var listener = new HttpListener())
            {
                listener.Prefixes.Add(ListenerUri);
                listener.Start();
                token.Register(() => listener.Abort());
                while (!token.IsCancellationRequested)
                {
                    var context = await listener.GetContextAsync();

                    var id = Thread.CurrentThread.ManagedThreadId;
                    _countByThreadId.AddOrUpdate(id, 1, (id, count) => count + 1);
                    var html     = $"<html><body>Thread {id}, request {_countByThreadId[id]}</body></html>";
                    var bytes    = Encoding.UTF8.GetBytes(html);
                    var response = context.Response;
                    response.ContentLength64 = bytes.Length;
                    using (var output = response.OutputStream)
                    {
                        response.OutputStream.Write(bytes, 0, bytes.Length);
                    }
                }
                listener.Stop();
            }
        }
コード例 #15
0
ファイル: HttpServer.cs プロジェクト: liumx2007/ControlCenter
 private void RunHttpServerThread()
 {
     this._httpListenThread = new Thread(new ThreadStart(() =>
     {
         HttpListener httpListener = new HttpListener();
         try
         {
             this._httpImplanter.MakeHttpPrefix(httpListener);
             httpListener.Start();
         }
         catch (Exception var_1_1F)
         {
             Logger.Exit("无法启动服务器监听,请检查网络环境。");
         }
         this._httpImplanter.Start();
         IAsyncResult asyncResult = null;
         while (!this._terminated)
         {
             while (asyncResult == null || asyncResult.IsCompleted)
             {
                 asyncResult = httpListener.BeginGetContext(new AsyncCallback(this.ProcessHttpRequest), httpListener);
             }
             this._ready = true;
             Thread.Sleep(10);
         }
         httpListener.Stop();
         httpListener.Abort();
         httpListener.Close();
         this._httpImplanter.Stop();
     }));
     this._httpListenThread.IsBackground = true;
     this._httpListenThread.Start();
 }
コード例 #16
0
        protected override void OnUnregister(IChannelListener listener, bool abort)
        {
            lock (opened_listeners) {
                if (http_listener == null)
                {
                    return;
                }
                if (http_listener.IsListening)
                {
                    if (abort)
                    {
                        http_listener.Abort();
                    }
                    else
                    {
                        http_listener.Close();
                    }
                }
                ((IDisposable)http_listener).Dispose();

                opened_listeners.Remove(listener.Uri);
            }

            http_listener = null;
        }
コード例 #17
0
        public static void BuildHttpListener()
        {
            if (_httpListener != null)
            {
                _httpListener.Abort();
                _httpListener = null;
            }
            _onComplete = null;

            string serverUrl = string.Format("http://127.0.0.1:{0}", SpreadsheetManager.Config.PORT);

            _httpListener = new HttpListener();
            _httpListener.Prefixes.Add(serverUrl + "/");
            _httpListener.Start();
            _httpListener.BeginGetContext(new AsyncCallback(ListenerCallback), _httpListener);

            _onComplete += GetAuthComplete;

            string request = "https://accounts.google.com/o/oauth2/v2/auth?";

            request += "client_id=" + Uri.EscapeDataString(SpreadsheetManager.Config.CLIENT_ID) + "&";
            request += "redirect_uri=" + Uri.EscapeDataString(serverUrl) + "&";
            request += "response_type=" + "code" + "&";
            request += "scope=" + Uri.EscapeDataString("https://www.googleapis.com/auth/spreadsheets") + "&";
            request += "access_type=" + "offline" + "&";
            request += "prompt=" + "consent" + "&";


            Application.OpenURL(request);
        }
コード例 #18
0
        /// <summary>
        /// Stop the http listener.
        /// </summary>
        public void Stop()
        {
            try
            {
                // Stop the service.
                _running = false;

                if (_listener != null)
                {
                    _listener.Abort();
                }
            }
            catch (Exception ex)
            {
                // Log the error.
                LogHandler.WriteTypeMessage(
                    ex.Message,
                    MethodInfo.GetCurrentMethod(),
                    Nequeo.Net.Common.Helper.EventApplicationName);
            }
            finally
            {
                if (_listener != null)
                {
                    _listener.Close();
                }
            }
        }
コード例 #19
0
        public void Stop()
        {
            lock (this) {
                if (!running)
                {
                    return;
                }

                stop_requested = true;
                listener.Abort();

                // busy wait, oh well
                if (Debug)
                {
                    Console.WriteLine("waiting for server to stop");
                }
                while (running)
                {
                }
                if (Debug)
                {
                    Console.WriteLine("  > done waiting for server to stop");
                }
            }
        }
コード例 #20
0
        private void abort()
        {
            lock (_sync)
            {
                if (_state != ServerState.Start)
                {
                    return;
                }

                _state = ServerState.ShuttingDown;
            }

            try
            {
                try
                {
                    _services.Stop(1006, String.Empty);
                }
                finally
                {
                    _listener.Abort();
                }
            }
            catch
            {
            }

            _state = ServerState.Stop;
        }
コード例 #21
0
        public void Stop()
        {
            LogMsg("Server.KillServer() is called, killing the server");

            //if (_httpListener.Prefixes.Any()) _httpListener.Prefixes.Clear();
            _httpListener.Abort();
        }
コード例 #22
0
 public void Shutdown()
 {
     try
     {
         var counter = 10;
         while (_listener.IsListening && counter-- > 0)
         {
             _listener.Abort();
             _listener.Stop();
             _listener.Close();
             if (_listener.IsListening)
             {
                 System.Threading.Thread.Sleep(50);
             }
         }
     }
     catch (ObjectDisposedException)
     {
         // that's ok
     }
     catch (Exception e)
     {
         Logger.ErrorException(e, "Error while shutting down http server");
     }
 }
コード例 #23
0
        private void abort()
        {
            lock (_sync) {
                if (_state != ServerState.Start)
                {
                    return;
                }

                _state = ServerState.ShuttingDown;
            }

            try {
                _services.Stop(1006, String.Empty);
            }
            catch (Exception ex) {
                _log.Fatal(ex.Message);
                _log.Debug(ex.ToString());
            }

            try {
                _listener.Abort();
            }
            catch (Exception ex) {
                _log.Fatal(ex.Message);
                _log.Debug(ex.ToString());
            }

            _state = ServerState.Stop;
        }
コード例 #24
0
        // stop the processing thread
        public void Stop()
        {
            try
            {
                if (httpListener != null)
                {
                    // check if we're listening for a request
                    if (httpListener.IsListening)
                    {
                        // tell the processing thread to exit
                        exitFlag.Set();
                        // stop listening and kill everything that may be in the queue
                        try
                        {
                            httpListener.Abort();
                        }
                        catch { }
                    }
                }
            }
            catch { }

            try
            {
                bool foo = Initialization.Default.UnInitialize();
            }
            catch (Exception ex)
            {
                Functions.WriteLineToLogFile("Webserver: Error uninitialising:");
                Functions.WriteExceptionToLogFile(ex);
            }
        }
コード例 #25
0
        /// <summary>
        /// Web Server Stop
        /// </summary>
        public void Stop_Server()
        {
            Log.Instance.Info("## HTTP Web Serve Stop ##");
            AddText(MSGVIEW.WEB, "서버 종료 중...");

            if (listener != null && listener.IsListening)
            {
                if (listenThread != null && listenThread.IsAlive)
                {
                    listenThread.Abort();
                    listenThread = null;
                    Log.Instance.Debug("Abort listenThread");
                }
                listener.Abort();
                listener = null;
                Log.Instance.Debug("Abort Previous HTTPListener");
            }
            else
            {
                Log.Instance.Info("## HTTP Web Serve is none ##");
                AddText(MSGVIEW.WEB, "서버가 실행되어 있지 않습니다.");
            }

            AddText(MSGVIEW.WEB, "서버종료 성공\n");
            Log.Instance.Info("## Local HTTP Web Server Stop Success ##");
        }
コード例 #26
0
ファイル: HttpServer.cs プロジェクト: clrjunkie/Kalinda
        public void Dispose()
        {
            EnsureHttpServerState(HttpServerState.Stopped);

            _listener.Abort();

            SetHttpServerState(HttpServerState.Disposed);
        }
コード例 #27
0
ファイル: HttpServer.cs プロジェクト: mikeage/open-brush
 private void OnDestroy()
 {
     if (m_HttpListener != null)
     {
         m_HttpListener.Abort();
         m_HttpListener = null;
     }
 }
コード例 #28
0
 // </snippet10>
 // <snippet11>
 public static void CheckTestUrl(HttpListener listener, HttpListenerRequest request)
 {
     if (request.RawUrl == "/www.contoso.com/test/NoReply")
     {
         listener.Abort();
         return;
     }
 }
コード例 #29
0
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     lock (root)
     {
         _httpListen?.Abort();
         _httpListen = null;
     }
 }
コード例 #30
0
ファイル: Program.cs プロジェクト: AndyDendy/local_s
 public void Stop()
 {
     users.WriteXml("users.xml");
     projects.WriteXml("project.xml");
     core.Abort();
     core.Close();
     core.Stop();
 }
コード例 #31
0
        static void Main(string[] args)
        {
            uriBaseAddress = args[0];
            if (!uriBaseAddress.EndsWith("/"))
                uriBaseAddress += "/";

            useV2Host = false;
            if (args.Length > 1)
                useV2Host = bool.Parse(args[1]);

            string waitHandleName = null;
            if (args.Length > 2)
                waitHandleName = args[2];

            serviceType = Assembly.GetExecutingAssembly()
                .GetTypes()
                .Single(t => !t.IsAbstract 
                    && typeof(Microsoft.OData.Service.IRequestHandler).IsAssignableFrom(t));

            HttpListener listener = new HttpListener();
            try
            {
                listener.Prefixes.Add(uriBaseAddress);
                listener.Start();
                listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception occurred:");
                Console.WriteLine(e.ToString());
                listener.Abort();
                Console.ReadLine();
            }

            // both of the following cases will block, so there is no need for a loop
            if (waitHandleName == "Debug" || string.IsNullOrEmpty(waitHandleName))
            {
                Console.WriteLine("Running in Debug mode, please press any key to exit");
                // blocks until key pressed
                Console.Read();
            }
            else
            {
                // if the wait handle name was specified on the command line, then the test infrastructure
                // must have created one for us to wait on
                // we do this instead of blocking on the command line because it has proven to be more robust
                // and much easier to shut down the service when disposing the workspace
                EventWaitHandle waitHandle = EventWaitHandle.OpenExisting(waitHandleName);

                // blocks until the wait handle is triggered by the test infrastructure
                waitHandle.WaitOne();
            }
        }