示例#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
 public void Dispose()
 {
     Client?.Dispose();
     Server?.Dispose();
 }