根据IP和端口号异步短时间判断服务器是否链接

/// <summary>
        /// 短时间判断是否可以连接
        /// </summary>
        /// <param name="ipe"></param>
        /// <returns></returns>
        public static bool TestConnet(IPEndPoint ipe)
        {
            bool b = false;
            var client = new TcpClient();
            try
            {
                var ar = client.BeginConnect(ipe.Address, ipe.Port, null, null);
                ar.AsyncWaitHandle.WaitOne(500);
                b = client.Connected;
                client.Close();
                return b;
            }
            catch
            {
                return b;
            }
            finally
            { client.Close(); }
        }

 

posted on 2017-07-30 23:19  LJD泊水  阅读(233)  评论(0编辑  收藏  举报