Пример #1
0
        static void Main(string[] args)
        {
            StartLogger();


            BaseServerModell baseServer = null;

            try
            {
                baseServer = new BaseServerModell(IPAddress.Parse(AppSettings.Settings.Host), AppSettings.Settings.Port);
                baseServer.Start();
                baseServer.Listen(5);
            }

            #region catch

            catch (Exception e)
            {
                Log.Error($"{e.Message}\r\n{e.InnerException?.Message}");
            }

            #endregion

            finally
            {
                if (baseServer != null)
                {
                    baseServer.Stop();
                    Task.WaitAll(baseServer.taskList.ToArray());
                }
            }
            Log.Debug("Server stopped...");
            Console.ReadLine();
        }
        public void MaxListenClients()
        {
            BaseServerModell baseServer = new BaseServerModell(IPAddress.Any, 55310);
            int maxClient = 3;

            baseServer.Start();
            Task.Run(() =>
            {
                baseServer.Listen(maxClient);
            });

            var task = Task.Run(() =>
            {
                Task.Delay(500).Wait();
            });

            task.Wait();

            Assert.That(baseServer.taskList.Count == maxClient);
            baseServer.Stop();
        }