这是测量Ping的正确方法吗?

时间:2019-07-06 22:01:59

标签: c# networking console-application ping

我真的很喜欢这个功能,但是我不确定,还有另一种更有效的方法吗?

此功能在其他游戏上给我带来相同的响声(很少出现0〜30ms,这是错误的)。就像在Pubg Europe Server中是89ms一样,如果我将其连接到European Download Server,此函数将返回70〜110ms。

// Method To Calculate Internet Ping

static int GetPing()
{
    try
    {
        WebClient ping = new WebClient();
        Stopwatch stopwatch = new Stopwatch();
        stopwatch.Start();
        ping.DownloadFileAsync(new Uri(Server), Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\test10Gb.db");
        stopwatch.Stop();
        ping.CancelAsync();
        ping.Dispose();
        GC.Collect();
        return int.Parse(stopwatch.ElapsedMilliseconds.ToString());
    }
    catch (Exception) { }

    return -1;
}

0 个答案:

没有答案