本文整理汇总了C#中System.Net.Sockets.TcpClient.Open方法的典型用法代码示例。如果您正苦于以下问题:C# TcpClient.Open方法的具体用法?C# TcpClient.Open怎么用?C# TcpClient.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpClient
的用法示例。
在下文中一共展示了TcpClient.Open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClientConnectsAndDisconnectsWait
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: ClosingServerDisconnectsClients
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);
}
}