コード例 #1
0
		public void ClientConnectsAndDisconnectsWait()
		{
			using (var server = new TcpServer(Port, 1, Name, Version))
			using (var client = new TcpClient(new IPEndPoint(IPAddress.Loopback, Port), Version))
			{
				server.Start();
				client.Open(true);

				Assert.AreEqual(ClientStatus.Ok, client.Status);
				Assert.AreEqual(1, server.Clients.Count);
				Assert.AreEqual(ClientStatus.Ok, server.Clients[0].Status);
				Assert.AreEqual(IPAddress.Loopback, server.Clients[0].RemoteEndpoint.Address);

				Assert.AreEqual(client.RemoteEndpoint, server.Clients[0].LocalEndpoint);
				Assert.AreEqual(client.LocalEndpoint, server.Clients[0].RemoteEndpoint);

				client.Close(true);
				Assert.AreEqual(ClientStatus.Closed, client.Status);
			}
		}
コード例 #2
0
		public void ClosingServerDisconnectsClients()
		{
			using (var server = new TcpServer(Port, 1, Name, Version))
			using (var client = new TcpClient(new IPEndPoint(IPAddress.Loopback, Port), Version))
			{
				server.Start();
				client.Open();
				Assert.AreEqual(ClientStatus.Ok, client.Status);

				server.Stop();
				Assert.AreEqual(0, server.Clients.Count);
				Assert.AreEqual(ClientStatus.Closed, client.Status);
			}
		}