当前位置: 首页>>代码示例>>C#>>正文


C# TcpClient.Equals方法代码示例

本文整理汇总了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;
                }
            }
        }
开发者ID:nesbocaj,项目名称:observer-pattern,代码行数:21,代码来源:ProxyConnection.cs

示例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;
        }
开发者ID:nesbocaj,项目名称:observer-pattern,代码行数:38,代码来源:ProxyConnection.cs


注:本文中的System.Net.Sockets.TcpClient.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。