本文整理汇总了C#中System.Net.Sockets.TcpClient.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# TcpClient.Equals方法的具体用法?C# TcpClient.Equals怎么用?C# TcpClient.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpClient
的用法示例。
在下文中一共展示了TcpClient.Equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public void Connect(TcpClient client, out SocketException ex)
{
ex = null;
for (int i = 0; i < 10 && !ReadWriteClient.Connected; i++)
{
try
{
if (client.Equals(ReadWriteClient))
client.Connect(_readWriteEndpoint);
if (client.Equals(ReadOnlyClient))
client.Connect(_readOnlyEndpoint);
break;
}
catch (SocketException se)
{
ex = se;
continue;
}
}
}
示例2: DoWhenConnected
public void DoWhenConnected(TcpClient client, Behavior behavior, SocketException se, out string result, string command = null)
{
result = null;
if (client.Connected)
{
BinaryReader reader = null;
BinaryWriter writer = null;
// if the behavior is set to read it'll only read, if write it'll only write, if readwrite it'll do both
if (behavior == Behavior.ReadOnly || behavior == Behavior.ReadWrite)
reader = new BinaryReader(client.GetStream());
if (behavior == Behavior.Write || behavior == Behavior.ReadWrite)
{
writer = new BinaryWriter(client.GetStream());
writer.Write(command);
}
if (behavior == Behavior.ReadOnly || behavior == Behavior.ReadWrite)
{
try
{
result = reader.ReadString();
}
catch (System.IO.IOException ioe)
{
Console.WriteLine("Server has closed, and lef this message: {0}", ioe.Message);
}
}
if (client.Equals(ReadWriteClient))
{
client.Close();
client = new TcpClient();
}
}
else throw se;
}