探测端口!

wang_cheng_job wang_cheng_job 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我现在知道一个IP 61.203.487.84 和一个端口 123

要怎样使得这个探测的时间很短 不至于让用户等得不耐烦
下面是我的代码!
foreach (DataGridViewRow row in this.Dgvdete.Rows)
{
string ips= row.Cells[0].Value.ToString();
string port= row.Cells[1].Value.ToString();
IPAddress ip = IPAddress.Parse(ips);
DataGridViewImageCell imgcell = (DataGridViewImageCell)row.Cells[2];
imgcell.Value = imageList1.Images[1];
try
{
IPEndPoint point = new IPEndPoint(ip, Convert.ToInt32(port));
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.SendTimeout = 1;
sock.Connect(point);
imgcell.Value = imageList1.Images[0];
//Execute(string dosCommand, int milliseconds)
}
catch
{
imgcell.Value = imageList1.Images[1];
}
}

我现在的问题是当一个端口没有开发的时候!在探测的时候要等一段时间大约是(30多秒)
我该怎样使得它的探测时间在1到2秒!


...全文
评论 1
收藏 已收藏
分享
返回顶部
wang_cheng_job
C# 111,128 成员 642,536 内容