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


C# TcpClient.?.Close方法代码示例

本文整理汇总了C#中System.Net.Sockets.TcpClient.?.Close方法的典型用法代码示例。如果您正苦于以下问题:C# TcpClient.?.Close方法的具体用法?C# TcpClient.?.Close怎么用?C# TcpClient.?.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Sockets.TcpClient的用法示例。


在下文中一共展示了TcpClient.?.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WhoiseCheckState

        /// <summary>
        /// WHOis a domain to know is reserved or not 
        /// </summary>
        /// <param name="name">domain name</param>
        /// <param name="postfix">domain extension</param>
        /// <param name="server">server url</param>
        /// <param name="fullResponse">Set Whois info completely</param>
        /// <param name="ct">Cancellation Token</param>
        /// <returns>False if reserved and True if free</returns>
        public WhoisInfo WhoiseCheckState(string name, string postfix, string server, bool fullResponse)
        {
            var result = new WhoisInfo();

            try
            {
                //CONNECT TO TCP CLIENT OF WHOIS
                _tcpWhois = new TcpClient(server, 43);

                //SETUP THE NETWORK STREAM
                _nsWhois = _tcpWhois.GetStream();

                //GET THE DATA IN THE BUFFER FROM THE NETWORK STREAM
                _bfWhois = new BufferedStream(_nsWhois);

                _strmSend = new StreamWriter(_bfWhois);

                _strmSend.WriteLine(name + "." + postfix);
                _strmSend.Flush();


                try
                {
                    _strmRecive = new StreamReader(_bfWhois);
                    string response;

                    while ((response = _strmRecive.ReadLine()) != null)
                    {
                        result.Info += response + "\r\n";

                        if (!fullResponse &&
                            (result.Info.Contains("No match for ") || result.Info.Contains("no entries found")))
                            break;
                    }
                }
                catch (Exception exp)
                {
                    result.ErrorLogArgs = new WhoisErrorEventArgs(name, postfix, server, true, "WHOis Server Error: {0}",
                        exp.Message);

                    OnWhoisLog(result.ErrorLogArgs);
                    result.ReserveState = CheckState.Unchecked;
                    return result;
                }
            }
            catch (Exception exp)
            {
                result.ErrorLogArgs = new WhoisErrorEventArgs(name, postfix, server, true,
                    "No Internet Connection or Any other Fault.{1} Error: {0}", exp.Message, Environment.NewLine);

                OnWhoisLog(result.ErrorLogArgs);
                result.ReserveState = CheckState.Unchecked;
                return result;
            }

            //SEND THE WHO_IS SERVER ABOUT THE HOSTNAME
            finally
            {
                try
                {
                    _tcpWhois?.Close();
                }
                catch (Exception exp)
                {
                    result.ErrorLogArgs = new WhoisErrorEventArgs(name, postfix, server, false,
                        "Connection Closing Error: {0}",
                        exp.Message);

                    OnWhoisLog(result.ErrorLogArgs);
                }
            }

            if (string.IsNullOrEmpty(result.Info))
            {
                result.ReserveState = CheckState.Unchecked;
                result.ErrorLogArgs = new WhoisErrorEventArgs(name, postfix, server, true, "No Response: Unknown exception caused to couldn't response from server!");
                OnWhoisLog(result.ErrorLogArgs);
            }
            else
            {
                result.ReserveState = result.Info.Contains("No match for") ||
                                      result.Info.Contains("no entries found")
                    ? CheckState.Checked
                    : CheckState.Indeterminate;
            }

            return result;
        }
开发者ID:Behzadkhosravifar,项目名称:WHOis,代码行数:97,代码来源:WhoisHelper.cs


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