예제 #1
0
        private static void StartServer(int port)
        {
            try
            {
                server = new EasyTcpActionServer();
                server.Start(Port);

                bool exit = false;

                Console.WriteLine($">> Server started on ip: {LocalIP} (public ip adress: {PublicIP})!");
                Console.WriteLine($">> Server started listening to port {port}!");
                Console.WriteLine(">> Press escape to close the server ...");
                while (!exit)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Escape)
                    {
                        exit = true;
                    }
                }

                server.Dispose();

                Console.WriteLine(Environment.NewLine + ">> Server closed! Press any key to close the window ...");
                Console.ReadKey(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
예제 #2
0
        public void OnDisconnectClient()
        {
            var certificate = new X509Certificate2("certificate.pfx", "password");
            var port        = TestHelper.GetPort();

            using var server = new EasyTcpServer().UseSsl(certificate).Start(port);

            var client = new EasyTcpClient().UseSsl("localhost", true);
            int x      = 0;

            client.OnDisconnect += (o, c) => Interlocked.Increment(ref x);

            Assert.IsTrue(client.Connect(IPAddress.Any, port));
            server.Dispose();

            TestHelper.WaitWhileFalse(() => x == 1);
            Assert.AreEqual(1, x);
        }
예제 #3
0
        public void OnDisconnectClient()
        {
            var port = TestHelper.GetPort();

            using var server = new EasyTcpServer().Start(port);

            var client = new EasyTcpClient();
            int x      = 0;

            client.OnDisconnect += (o, c) => Interlocked.Increment(ref x);

            Assert.IsTrue(client.Connect(IPAddress.Any, port));
            TestHelper.WaitWhileFalse(() => server.ConnectedClientsCount == 1);
            server.Dispose();

            TestHelper.WaitWhileFalse(() => x == 1);
            Assert.AreEqual(1, x);
        }
예제 #4
0
파일: TestHelper.cs 프로젝트: Job79/EasyTcp
 public void Dispose()
 {
     Client?.Dispose();
     Server?.Dispose();
 }