.NET平()提供虚假超时? [英] .NET Ping() giving false timeouts?

查看:150
本文介绍了.NET平()提供虚假超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个遍历并发送一个ping到主机每秒的脚本。其目的是为了测试我的家庭网络上的无线性能。问题是,我似乎从我的剧本得到超时,而一个标准的ping -t无论是客户端(萍儿和pingEE)上没有这样的超时。事实上,没有一次在最后30分钟已经或者超时,而我的剧本已经收到超时答复每隔几分钟。

我的本质脚本如下。在任何情况下,当它发生,我的回答是TIMEDOUT以0毫秒的响应时间。是我的脚本导致错误超时?谢谢你。

编辑:更新code,以反映最新的变化,仍然有同样的行为。

 ,而(真)
{
    System.Threading.Thread.Sleep(延迟);
    VAR建设者=新的StringBuilder();

    hosts.ForEach(H =>
    {
        VAR缓冲区=新的字节[32];
        VAR回复= ping.Send(H,4000,缓冲器,新的PingOptions(600,真));
        VAR错误= reply.Status!= IPStatus.Success || reply.RoundtripTime> maxRoundTrip;

        如果(详细||错误)
        {
            builder.AppendFormat({0}:{1}({2}毫秒)中,h,reply.Status,reply.RoundtripTime);
            builder.Append(Environment.NewLine);

            如果(错误)
            {
                WRITELOG(H,回复);
                SendEmail(H,回复);
            }
        }
    });

    Console.WriteLine(DateTime.Now);
    Console.WriteLine(builder.ToString());
}
 

解决方案

我可能已经想通了。我用的是NetBIOS名称为有问题的机器。我猜测,它做了一个平每一次,​​它被分解的IP查询的往返,被超时。当我使用的只是IP,它的工作就好了,并没有超时。

感谢您的输入。

I have a script that is looping through and sending a ping to a host every second. The purpose of which is to test wireless performance on my home network. The issue is, I seem to be getting timeouts from my script, while a standard "ping -t" on either client (pingER and pingEE) have no such timeouts. In fact, not once in the last 30 minutes has either timed out, while my script has received timeout replies every few minutes.

My essential script is below. In all cases, when it does happen, my reply is TimedOut with a response time of 0ms. Is my script causing false timeouts? Thanks.

EDIT: updated code to reflect newest changes, still having same behavior.

while (true)
{
    System.Threading.Thread.Sleep(delay);
    var builder = new StringBuilder();

    hosts.ForEach(h =>
    {
        var buffer = new byte[32];
        var reply = ping.Send(h, 4000, buffer, new PingOptions(600, true));
        var error = reply.Status != IPStatus.Success || reply.RoundtripTime > maxRoundTrip;

        if (verbose || error)
        {
            builder.AppendFormat("{0}: {1} ({2}ms)", h, reply.Status, reply.RoundtripTime);
            builder.Append(Environment.NewLine);

            if (error)
            {
                WriteLog(h, reply);
                SendEmail(h, reply);
            }
        }
    });

    Console.WriteLine(DateTime.Now);
    Console.WriteLine(builder.ToString());
}

解决方案

I might have figured it out. I was using the netbios name for the machine in question. I'm guessing that each time it did a ping, it was factoring in the IP lookup in the round trip and was timing out. When I used just the IP, it worked just fine and hasn't timed out.

Thanks for the input.

这篇关于.NET平()提供虚假超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆