Пример #1
0
        public void SendReboot()
        {
            while (RequestProccess.ThreadCount > 1)
            {
                Thread.Sleep(300);
                //wait...
            }

            ServerSocket.Close();
            ServerSocket.Dispose();
            ServerSocket = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            ServerSocket.Bind(new IPEndPoint(IPAddress.Any, Port));
            ServerSocket.Listen(0);
            ServerSocket.BeginAccept(AcceptCallback, null);

            RebootRequest?.Invoke();
        }
Пример #2
0
        public void Start(bool waitForUserTypeExit = true)
        {
            if (Started)
            {
                throw new Exception("Server already has been started.");
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            Initialize();
            ServerSocket.Bind(new IPEndPoint(IPAddress.Any, Port));

            ServerSocket.Listen(0);
            ServerSocket.BeginAccept(AcceptCallback, null);
            Started = true;
            ServerStarted?.Invoke();
            RunServerStartupTasks();
            sw.Stop();
            LogController.WriteLog(new ServerLog($"Server started in {sw.ElapsedMilliseconds}ms", "Server", "Start"));
            LogController.WriteLog(new ServerLog($"Running at port {Port}"));
            Console.WriteLine("Type 'exit' to stop; 'reboot' to send reboot request event...");
            string line = "";

            if (waitForUserTypeExit)
            {
                while (line != "exit")
                {
                    line = Console.ReadLine();
                    if (line == "reboot")
                    {
                        RebootRequest?.Invoke();
                    }
                }
            }
        }