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