Exemple #1
0
        private void stopToolStripMenuItem_Click(Object sender, EventArgs e)
        {
            listener?.Stop();
            listener?.Close();

            stopToolStripMenuItem.Enabled  = false;
            startToolStripMenuItem.Enabled = true;
        }
Exemple #2
0
        private static void HttpListenerBasedListener()
        {
            HttpListener listener = null;

            try
            {
                listener = new HttpListener()
                {
                    IgnoreWriteExceptions = true
                };                                                              // IsSupported... we assume so.
                listener.Prefixes.Add("http://localhost:5000/");
                listener.Start();
                Console.WriteLine("Waiting for a connection on http://localhost:5000 ...");

                byte[] answer = Encoding.UTF8.GetBytes("Hello World!");

                HttpListenerContext context;
                while ((context = listener.GetContext()) != null)
                {
                    context.Response.ContentLength64 = answer.Length;
                    context.Response.OutputStream.Write(answer, 0, answer.Length);
                    context.Response.OutputStream.Close();
                }
            }
            catch (Exception exc)
            {
                Console.Error.WriteLine(exc.Message);
            }
            finally
            {
                listener?.Stop();
            }
        }
Exemple #3
0
 public void Stop()
 {
     _listener?.Stop();
     _server?.Abort();
     _listener = null;
     _server   = null;
 }
Exemple #4
0
 public void Stop()
 {
     if (_listener?.IsListening ?? false)
     {
         _listener?.Stop();
     }
 }
Exemple #5
0
        public static void StopWebServer(bool log = true)
        {
            if (!Config.EnableWebServer)
            {
                return;
            }

            HttpListener expiredWebListener = WebListener;

            WebListener = null;

            HttpListener expiredBuyListener = BuyListener;

            BuyListener = null;
            HttpListener expiredIPNListener = IPNListener;

            IPNListener = null;


            WebServerStarted = false;
            expiredWebListener?.Stop();
            expiredBuyListener?.Stop();
            expiredIPNListener?.Stop();

            if (log)
            {
                SEnvir.Log("Web Server Stopped.");
            }
        }
Exemple #6
0
 /// <summary>
 /// Tear down the server and dispose of background workers.
 /// </summary>
 /// <param name="disposing">Disposing.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _Listener?.Stop();
         _TokenSource.Cancel();
     }
 }
        /// <summary>
        /// Stop logic
        /// </summary>
        /// <returns></returns>
        public async Task Stop()
        {
            _infoTimer?.Stop();
            _stopHttpListener = true;
            _httpListener?.Stop();

            await _mqttClient?.StopAsync();
        }
Exemple #8
0
        public void Dispose()
        {
            Display?.Dispose();
            Display = null;

            webListener?.Stop();
            webListener = null;
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _httpListener?.Stop();
         _httpListener?.Close();
     }
 }
 public void Stop()
 {
     Listener?.Close();
     Listener?.Stop();
     Listener  = null;
     isStarted = false;
     AirportStatUtils.AirportStatsLogger(Log.FromPool("Listener Stopped").WithCodepoint());
 }
Exemple #11
0
 /// <summary>
 /// 停止服务
 /// </summary>
 /// <returns></returns>
 public virtual bool Stop()
 {
     if (Interlocked.CompareExchange(ref _isStarted, 0, 1) != 1)
     {
         return(true);
     }
     _httpListen?.Stop();
     return(true);
 }
 private static void StopHttpShow()
 {
     try
     {
         httpListener?.Stop();
     }
     catch { }
     httpListener?.Close();
 }
Exemple #13
0
        public static void StartWebServer(bool log = true)
        {
            try
            {
                WebCommandQueue = new ConcurrentQueue <WebCommand>();

                WebListener = new HttpListener();
                WebListener.Prefixes.Add(Config.WebPrefix);

                WebListener.Start();
                WebListener.BeginGetContext(WebConnection, null);

                BuyListener = new HttpListener();
                BuyListener.Prefixes.Add(Config.BuyPrefix);

                IPNListener = new HttpListener();
                IPNListener.Prefixes.Add(Config.IPNPrefix);

                BuyListener.Start();
                BuyListener.BeginGetContext(BuyConnection, null);

                IPNListener.Start();
                IPNListener.BeginGetContext(IPNConnection, null);



                WebServerStarted = true;

                if (log)
                {
                    SEnvir.Log("Web Server Started.");
                }
            }
            catch (Exception ex)
            {
                WebServerStarted = false;
                SEnvir.Log(ex.ToString());

                if (WebListener != null && WebListener.IsListening)
                {
                    WebListener?.Stop();
                }
                WebListener = null;

                if (BuyListener != null && BuyListener.IsListening)
                {
                    BuyListener?.Stop();
                }
                BuyListener = null;

                if (IPNListener != null && IPNListener.IsListening)
                {
                    IPNListener?.Stop();
                }
                IPNListener = null;
            }
        }
Exemple #14
0
 /// <summary>
 /// Stops listening for incoming connections.
 /// </summary>
 public void StopListening()
 {
     Listening = false;
     ReleaseClients();
     httpListener?.Stop();
     httpListener?.Close();
     httpListener = null;
     nat?.DeletePortMapAsync(portMap);
 }
Exemple #15
0
        private static void Main(string[] args)
        {
            XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net_server.config"));

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.Name           = "Entry";

            Settings = new SimpleSettings("server");
            Database = new Database(
                Settings.GetValue <string>("db_host", "127.0.0.1"),
                Settings.GetValue <string>("db_database", "rotmgprod"),
                Settings.GetValue <string>("db_user", "root"),
                Settings.GetValue <string>("db_auth", ""));
            GameData = new XmlData();

            InstanceId              = Guid.NewGuid().ToString();
            Console.CancelKeyPress += (sender, e) => e.Cancel = true;

            var port = Settings.GetValue <int>("port", "8888");

            if (RunPreCheck(port))
            {
                try
                {
                    listener = new HttpListener();
                    listener.Prefixes.Add($"http://*:{port}/");
                    //listener.Prefixes.Add($"http://localhost:{port}/");
                    listener.Start();

                    listener.BeginGetContext(ListenerCallback, null);
                    Logger.Info($"Listening at port {port}...");
                }catch (Exception ex)
                {
                    Logger.Error($"Error: {ex.Message}");
                }
            }
            else
            {
                Logger.Error($"Port {port} is occupied. Can't start listening...\nPress ESC to exit.");
            }

            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                ;
            }

            Logger.Info("Terminating...");
            //To prevent a char/list account in use if
            //both servers are closed at the same time
            while (currentRequests.Count > 0)
            {
                ;
            }
            listener?.Stop();
            GameData.Dispose();
        }
 public void Stop()
 {
     // TODO: thread safety
     _stop = true;
     _listener?.Stop();
     _listener?.Close();
     _handler?.Dispose();
     _listener = null;
     SetStatus(HttpAsyncHostStatus.Initialised);
 }
Exemple #17
0
 public static void Stop()
 {
     try
     {
         listener?.Stop();
     }
     catch (Exception error)
     {
     }
 }
        public void Stop()
        {
            if (_cancellationToken is null)
            {
                return;
            }

            _listener?.Stop();
            _cancellationToken.Cancel();
            _logger.LogInformation("Stopped");
        }
Exemple #19
0
 public void Dispose()
 {
     try
     {
         _listener?.Stop();
     }
     catch (ObjectDisposedException)
     {
         // swallow this exception just in case
     }
 }
Exemple #20
0
 /// <summary>
 /// 停止服务
 /// </summary>
 public void Stop()
 {
     try
     {
         listener?.Stop();
     }
     catch (Exception ex)
     {
         Debug.LogError(ex);
     }
 }
 public void Disconnect()
 {
     try
     {
         _listener?.Stop();
         _listener?.Close();
     }
     catch (Exception ex)
     {
         Log.Out("Caught exception when disconnecting: {0}", ex.ToString());
     }
 }
Exemple #22
0
        private static void Main(string[] args)
        {
            Console.Title = "TEST Account Server";
            {
                XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net_server.config"));

                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
                Thread.CurrentThread.Name           = "Entry";

                Settings = new SimpleSettings("server");
                Database = new Database(
                    Settings.GetValue <string>("db_host", "127.0.0.1"),
                    Settings.GetValue <string>("db_database", "Nxl"),
                    Settings.GetValue <string>("db_user", "root"),
                    Settings.GetValue <string>("db_auth", ""));
                GameData = new XmlData();

                InstanceId              = Guid.NewGuid().ToString();
                Console.CancelKeyPress += (sender, e) => e.Cancel = true;

                var port = Settings.GetValue <int>("port", "80");

                if (RunPreCheck(port))
                {
                    listener = new HttpListener();
                    listener.Prefixes.Add($"http://*:{port}/");
                    listener.Start();

                    listener.BeginGetContext(ListenerCallback, null);
                    Logger.Info($"TEST account server is now running!");
                }
                else
                {
                    Logger.Error($"Port {port} is occupied. Can't start listening...\nPress ESC to exit. \nPlease check if you are running any programs that could use the port \nTry end tasking the srvrhost process.");
                }

                while (Console.ReadKey(true).Key != ConsoleKey.Escape)
                {
                    ;
                }

                Logger.Info("Terminating...");
                //To prevent a char/list account in use if
                //both servers are closed at the same time
                while (currentRequests.Count > 0)
                {
                    ;
                }
                listener?.Stop();
                GameData.Dispose();
            }
        }
Exemple #23
0
        static void Main(string[] args)
        {
            LoggerFactory.Factory = new Log4NetAdapter();

            ShowInfo();

            var result = Parser.Default.ParseArguments <CommandLineOptions>(args);

            var exitCode = result
                           .MapResult(
                options =>
            {
                Cloud.Init(options.UserAgent);

                var webdavProtocol = "http";
                var webdavIp       = "127.0.0.1";
                var webdavPort     = options.Port;
                var webdavHost     = string.IsNullOrWhiteSpace(options.Host)
                        ? $"{webdavProtocol}://{webdavIp}"
                        : options.Host.TrimEnd('/');

                var cancellationTokenSource = new CancellationTokenSource();
                var httpListener            = new HttpListener();
                try
                {
                    httpListener.Prefixes.Add($"{webdavHost}:{webdavPort}/");
                    httpListener.AuthenticationSchemes = AuthenticationSchemes.Basic;
                    httpListener.Start();

                    // Start dispatching requests
                    DispatchHttpRequestsAsync(httpListener, cancellationTokenSource.Token, options.MaxThreadCount);

                    // Wait until somebody presses return
                    Logger.Info($"WebDAV server running at {webdavHost}:{webdavPort}");
                    while (Console.ReadKey().KeyChar != 'x')
                    {
                    }
                }
                finally
                {
                    cancellationTokenSource?.Cancel();
                    httpListener?.Stop();
                }
                return(0);
            },
                errors => 1);

            if (exitCode > 0)
            {
                Environment.Exit(exitCode);
            }
        }
Exemple #24
0
 public void StopHttpTasks()
 {
     // HTTP リスナタスク停止
     KeepListen = false;
     try
     {
         HTTPListener?.Stop();
     }
     catch (Exception)
     {
         //
     }
 }
Exemple #25
0
        public void Stop()
        {
            if (!_isStarted)
            {
                throw Error.InvalidOperation("Server not started");
            }

            _httpListener?.Stop();
            _listenerTask?.Wait();
            _httpListener = null;

            _isStarted = false;
        }
Exemple #26
0
 public void StopServer()
 {
     try
     {
         Console.WriteLine("Weber server shutdown");
         IsActive = false;
         _httpListener?.Stop();
     }
     catch (Exception e)
     {
         throw new Exception($"HttpTransport StopServer Error: {e.Message}");
     }
 }
Exemple #27
0
        public void On(string uri, Action <ReceivedResults> callback)
        {
            _listener?.Stop();

            _listener = new HttpListener();
            _listener.Prefixes.Add(uri);

            _callback = callback;

            //Console.WriteLine($"Listening.. {uri}");
            _listener.Start();

            RunWorkerThread(_listener, _callback);
        }
Exemple #28
0
        public void StopMining()
        {
            Program.Print("[INFO] Master instance stopping...");
            m_isOngoing = false;

            NetworkInterface.OnGetMiningParameterStatus -= NetworkInterface_OnGetMiningParameterStatus;
            NetworkInterface.OnNewChallenge             -= NetworkInterface_OnNewChallenge;
            NetworkInterface.OnNewTarget     -= NetworkInterface_OnNewTarget;
            NetworkInterface.OnNewDifficulty -= NetworkInterface_OnNewDifficulty;
            NetworkInterface.OnStopSolvingCurrentChallenge -= NetworkInterface_OnStopSolvingCurrentChallenge;

            m_Listener?.Stop();
            m_Listener?.Close();
        }
Exemple #29
0
        private static void Main(string[] args)
        {
            Console.Title = "Zy's Realm - Server";

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.Name           = "Entry";

            Settings = new SimpleSettings("server");
            Database = new Database(
                Settings.GetValue <string>("db_host", "127.0.0.1"),
                Settings.GetValue <string>("db_database", "rotmgprod"),
                Settings.GetValue <string>("db_user", "root"),
                Settings.GetValue <string>("db_auth", ""));
            GameData = new XmlData();

            InstanceId              = Guid.NewGuid().ToString();
            Console.CancelKeyPress += (sender, e) => e.Cancel = true;

            var port = Settings.GetValue <int>("port", "80");

            if (RunPreCheck(port))
            {
                listener = new HttpListener();
                listener.Prefixes.Add($"http://*:{port}/");
                listener.Start();

                listener.BeginGetContext(ListenerCallback, null);
                Console.WriteLine($"Listening at port {port}...");
            }
            else
            {
                Console.WriteLine($"Port {port} is occupied. Can't start listening...\nPress ESC to exit.");
            }

            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                ;
            }

            Console.WriteLine("Terminating...");
            //To prevent a char/list account in use if
            //both servers are closed at the same time
            while (currentRequests.Count > 0)
            {
                ;
            }
            listener?.Stop();
            GameData.Dispose();
        }
 public void StopService()
 {
     try
     {
         if (_listener.IsListening)
         {
             _listener?.Stop();
             _listener?.Abort();
             _listener?.Close();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Exemple #31
0
	private static void Listen ()
	{
		HttpListener listener = new HttpListener ();
		listener.Prefixes.Add ("http://127.0.0.1:8080/a/");
		listener.Start ();

		HttpListenerResponse response = listener.GetContext().Response;
		response.ContentType = "text/xml";

		byte [] buffer = Encoding.UTF8.GetBytes ("<ok/>");
		response.ContentLength64 = buffer.Length;
		Stream output = response.OutputStream;
		output.Write (buffer, 0, buffer.Length);
		output.Close ();
		listener.Stop ();
	}
Exemple #32
0
        public static async Task SimpleRequest_Succeeds()
        {
            string url = UrlPrefix.CreateLocal();
            const string expectedResponse = "hello from HttpListener";

            using (HttpListener listener = new HttpListener())
            {
                listener.Prefixes.Add(url);
                listener.Start();

                var serverContextTask = listener.GetContextAsync();

                using (HttpClient client = new HttpClient())
                {
                    var clientTask = client.GetStringAsync(url);

                    var serverContext = await serverContextTask;
                    using (var response = serverContext.Response)
                    {
                        var responseBuffer = Encoding.UTF8.GetBytes(expectedResponse);
                        response.ContentLength64 = responseBuffer.Length;

                        using (var output = response.OutputStream)
                        {
                            await output.WriteAsync(responseBuffer, 0, responseBuffer.Length);
                        }
                    }

                    var clientString = await clientTask;

                    Assert.Equal(expectedResponse, clientString);
                }

                listener.Stop();
            }
        }
    public void Run()
    {
        HttpListener listener = new HttpListener();
        listener.Prefixes.Add("http://localhost:8080/");
        listener.Start();

        // Wait for a request
        HttpListenerContext context = listener.GetContext();
        HttpListenerRequest request = context.Request;

        // process the request
        string path = request.Url.AbsolutePath;
        string responseString;

        try
        {
            responseString = handler(context);
        }
        catch (Exception e)
        {
            responseString = e.ToString();
        }

        // write the response
        HttpListenerResponse response = context.Response;
        System.IO.Stream output = response.OutputStream;

        if (!String.IsNullOrEmpty(responseString))
        {
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
            response.ContentLength64 = buffer.Length;
            output.Write(buffer, 0, buffer.Length);
        }
        output.Close();

        // shut down the listener
        listener.Stop();
    }