根據IP和端口號異步短時間判斷服務器是否鏈接
阿新 • • 發佈:2017-07-31
端口號 end begin pcl connect close returns nco null
/// <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(); } }
根據IP和端口號異步短時間判斷服務器是否鏈接