Exemplo n.º 1
0
 public void Stop()
 {
     if (_httpListener != null)
     {
         _httpListener.Close();
         _httpListener.Dispose();
         _httpListener = null;
     }
 }
Exemplo n.º 2
0
        public void StartServer(String ip, String port)
        {
            try
            {
                if (_listener == null)
                {
                    if (String.IsNullOrWhiteSpace(ip))
                    {
                        ExceptionHelper.ShowErrorMsg(_view.TryFindResource("StrIpEmpty") as String);
                    }
                    Boolean isValid = NetworkHelper.IsValidIp(ip, out System.Net.IPAddress ipAddress);
                    if (!isValid)
                    {
                        ExceptionHelper.ShowErrorMsg(_view.TryFindResource("StrIpWrong") as String);
                    }

                    if (String.IsNullOrWhiteSpace(port))
                    {
                        ExceptionHelper.ShowErrorMsg(_view.TryFindResource("StrPortEmpty") as String);
                    }
                    isValid = Int32.TryParse(port, out Int32 portInt);
                    if (!isValid)
                    {
                        ExceptionHelper.ShowErrorMsg(_view.TryFindResource("StrPortWrong") as String);
                    }
                    else if (portInt < 0 || portInt > 65535)
                    {
                        ExceptionHelper.ShowErrorMsg(_view.TryFindResource("StrPortWrongRange") as String);
                    }

                    SettingsHelper.Ip   = ip;
                    SettingsHelper.Port = port;

                    _listener = new HttpListener(AddToList);
                    _listener.Start(ipAddress, portInt);
                    _view.SetState(true);
                }
                else
                {
                    _listener.Dispose();
                    _listener = null;
                    _view.SetState(false);
                }
            }
            catch (Exception e)
            {
                if (_listener != null)
                {
                    _listener.Dispose();
                    _listener = null;
                }

                ExceptionHelper.ShowErrorMsg(_view.TryFindResource("StrStartFail") as String, e);
            }
        }
Exemplo n.º 3
0
        private void buttonStartProxy_Click(object sender, EventArgs e)
        {
            //System.Net.IPAddress[] test = System.Net.Dns.GetHostEntry("10.88.1.253").AddressList;
            if (buttonStartProxy.Text == "Start Proxy")
            {
                int por = 0;
                //string port = textBoxPort.Text;
                try
                {
                    por = Convert.ToInt32(numericUpDownPort.Value);//Convert.ToInt32(port);
                    lis = new HttpListener(por);

                    lis.Start();
                    buttonStartProxy.Text     = "Stop Proxy";
                    numericUpDownPort.Enabled = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Port number wrong!\n" + ex.Message);
                }
            }
            else
            {
                buttonStartProxy.Text     = "Start Proxy";
                numericUpDownPort.Enabled = true;

                if (lis != null)
                {
                    lis.Dispose();
                }
            }
        }
Exemplo n.º 4
0
        public void TestInactiveServer()
        {
            Assert.Throws <WebException>(() => {
                connection.ConnectionTimeout = TimeSpan.FromMilliseconds(100);
#if NETSTANDARD1_5
                listener.Dispose();
#else
                listener.Stop();
#endif
                RecieveFirst();
            });
        }
Exemplo n.º 5
0
 protected override void OnStop()
 {
     try
     {
         httpListner?.Dispose();
         radiusServer?.Stop();
     }
     catch (Exception ex)
     {
         Log.Write(MethodBase.GetCurrentMethod(), ex);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Shut down the Web Service
        /// </summary>
        public override void Stop()
        {
            if (HttpListener != null)
            {
                HttpListener.Dispose();
                HttpListener = null;
            }

            if (Listener != null)
            {
                Listener.Prefixes.Remove(UrlPrefix);
            }

            base.Stop();
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            int port = 18081;

            var listener = new HttpListener(IPAddress.Any, port);

            listener.Request += HandleRequest;
            listener.Start();

            Console.WriteLine($"Start an internet browser and navigate to http://localhost:{port}");

            Console.WriteLine("Press any key to stop listener");

            Console.ReadKey();
            listener.Close();
            listener.Dispose();
        }
Exemplo n.º 8
0
        private void Dispose(bool disposing)
        {
            Close(true);

            if (!disposing)
            {
                return;
            }

            _timer?.Dispose();
            _sock?.Dispose();
            _ms?.Dispose();
            _iStream?.Dispose();
            _oStream?.Dispose();
            Stream?.Dispose();
            _lastListener?.Dispose();
            ClientCertificate?.Dispose();
        }
Exemplo n.º 9
0
        public void TestEnablement()
        {
            Uri    localUri     = new Uri("http://localhost:8000/kmlcam/xyz");
            Action clientAction = () => HttpGet(localUri);

            using (HttpListener ws = new HttpListener(localUri, path => s2b($"~/{path}/~")))
            {
                Assert.ThrowsAny <Exception>(clientAction); // created but not enabled; should throw exception
                ws.Enable();
                clientAction.Invoke();                      // should be available now
                ws.Disable();
                Assert.ThrowsAny <Exception>(clientAction); // disabled, not available; should throw exception
                ws.Enable();
                clientAction.Invoke();                      // re-enabled, available again
                ws.Dispose();
                Assert.ThrowsAny <Exception>(clientAction); // disposed, not available; should throw exception
            }
        }
Exemplo n.º 10
0
        public static void Main(string[] args)
        {
            int port = 18081;

            var listener = new HttpListener(IPAddress.Any, port);

            listener.Request += HandleRequest;
            listener.Start();

            bool isListening = listener.IsListening;

            Console.WriteLine("isListening = {0}", isListening);

            Console.WriteLine("Press any key to stop listener");

            Console.ReadKey();
            listener.Close();
            listener.Dispose();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Disposes the current HttpServer
        /// </summary>
        private void DisposeHttpServer()
        {
            foreach (var socket in _webSocketConnections)
            {
                // Dispose the connection
                socket.Dispose();
            }

            _webSocketConnections.Clear();

            if (HttpServer != null)
            {
                HttpServer.WebSocketConnected -= HttpServer_WebSocketConnected;
                HttpServer.Dispose();
            }

            if (HttpListener != null)
            {
                HttpListener.Dispose();
            }

            DisposeExternalWebSocketServer();
        }
Exemplo n.º 12
0
 public void Stop()
 {
     server.Dispose();
     tokenSource.Cancel();
     PinChanged = null;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Closes the server socket.
 /// </summary>
 public void Dispose()
 {
     listener.Dispose();
 }