Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows ping与C#PingReply不同吗_C#_Ping - Fatal编程技术网

Windows ping与C#PingReply不同吗

Windows ping与C#PingReply不同吗,c#,ping,C#,Ping,我有一个应用程序,当用户的互联网连接出现不可接受的延迟时通知用户(这是一个voip应用程序)。我使用以下代码检查延迟: IPAddress address = GetIpFromHost(this._testAddress); if (address != null) { this.SlowConnection = new SlowConnectionProblem(4, 100); //set the ping options, TTL 128 PingOptions pingOptions

我有一个应用程序,当用户的互联网连接出现不可接受的延迟时通知用户(这是一个voip应用程序)。我使用以下代码检查延迟:

IPAddress address = GetIpFromHost(this._testAddress);
if (address != null)
{
this.SlowConnection = new SlowConnectionProblem(4, 100);

//set the ping options, TTL 128
PingOptions pingOptions = new PingOptions(128, true);

//create a new ping instance
Ping ping = new Ping();

//32 byte buffer (create empty)
byte[] buffer = new byte[32];

while (!_slowConnectionChecker.CancellationPending)
{
    System.Threading.Thread.Sleep(this._checkInterval);
    try
    {
        //send the ping 4 times to the host and record the returned data.
        //The Send() method expects 4 items:
        //1) The IPAddress we are pinging
        //2) The timeout value
        //3) A buffer (our byte array)
        //4) PingOptions
        PingReply pingReply = ping.Send(address, 1000, buffer, pingOptions);

        //make sure we dont have a null reply
        if (!(pingReply == null))
        {
            if (pingReply.Status == IPStatus.Success)
            {
                int time = Convert.ToInt32(pingReply.RoundtripTime);
                this.SlowConnection.addNewPingTime(time);
                if (this.SlowConnection.HasProblem)
                {
                    addConnectionProblem(this.SlowConnection);
                }
                else
                {
                    removeConnectionProblem(this.SlowConnection);
                }
            }
        }
    }
    catch (PingException ex)
    {
    }
    catch (SocketException ex)
    {
    }
}
}
通常,包含上述方法的类计算平均ping。大多数情况下,它工作正常,但有几次我遇到了一个奇怪的情况,在我的应用程序中,我有一个高ping到google.pl的警告-大约128毫秒,同时windows ping显示我大约24毫秒


我仔细检查了代码,似乎没有错误

简而言之,是的,它们是相同的机制

PingReply
on MSDN

Ping类尝试发送Internet控制消息协议 (ICMP)将请求回送到远程计算机并接收信息 通过ICMP回显回复消息从计算机发送。Ping类使用 PingReply类的实例,以返回有关 操作,例如其状态和发送请求所用的时间 并收到回复

在windows中ping
命令

通过发送验证到另一台TCP/IP计算机的IP级别连接 Internet控制消息协议(ICMP)回显请求消息。这个 将显示相应回显回复消息的接收,以及 往返时间。Ping是用于 对连接、可达性和名称解析进行故障排除。使用 如果没有参数,ping将显示帮助

注意,IP级别的连接。您使用的是TCP还是UDP?这些都是基于IP的,可能会导致您的行为有所不同


同时

两个ICMP ping不太可能同时发生。结果往往会有所不同,因为IP路由不能保证每次尝试都是相同的。您是否考虑过ping您的呼叫服务器而不是google?这将为您提供更好的传输质量表示。您可能想要测量带宽,而不是ping。几百毫秒的时间不会像视频游戏那样打乱电话。您希望获得具有代表性的数据包大小的飞行时间,而不是微小的ICMP数据包


根据您的传输协议,ICMP ping可能无法为您提供通话质量的最佳表示。您应该考虑自定义ping实现,尽可能地模拟应用程序。p> 我的建议是用Wireshark捕获这两种类型的ICMP包,并对它们进行比较。我正在ping google,因为最终我的服务器可能会关闭,而google大部分时间都在运行。此util专门用于测试internet连接。我们还测试了延迟,因为当我们在某些公司安装我们的应用程序时,他们必须提供我们指定的最低带宽。另一方面,即使在连接带宽较高的情况下,延迟也可能很糟糕。通常,在使用我们的应用程序的不到一百家公司中,有一家公司今天一整天都在使用我们的应用程序—windows ping显示良好的结果,app—超过100毫秒。感谢您指出TCP/UDP可能存在的差异。我还没有发现如何强迫你。