在本地网络上调用集线器方法很慢

本文关键字:方法 集线器 调用 本地网络 | 更新日期: 2023-09-27 18:02:09

我使用的是SignalR。客户端DLL与使用SignalR的网站对话。当客户端和站点在同一台机器上时,它可以完美地工作。(调用hub方法是立即的)

然而,现在我通过网络在一台机器上设置了站点,调用(调用)平均需要2.5秒。(但)

我在1毫秒内启动机器。

使用Wireshark,我看到数据包在2.5秒后发送。

我调试了SignalR。它被卡在System.Threading.Task级别(在这里,在HttpHelper.cs中调用)
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Exceptions are flowed back to the caller.")]
    public static Task<Stream> GetHttpRequestStreamAsync(this HttpWebRequest request)
    {
        try
        {
            return Task.Factory.FromAsync<Stream>(request.BeginGetRequestStream, request.EndGetRequestStream, null);
        }
        catch (Exception ex)
        {
            return TaskAsyncHelper.FromError<Stream>(ex);
        }
    }

你知道什么可以减缓这个过程吗?

谢谢你。

ps:我已经使用SignalR聊天示例来重现延迟。

这是我的测试应用程序的(非常简单的)代码:
var connection = new HubConnection("http://IP:PORT/SITENAME/");
    var myHub = connection.CreateHubProxy("ChatHub");
    // Start the connection
    connection.Start().Wait();
    while (true)
    {
      string sMsg = string.Format("Hello world from winform! Sent(winform) at {0}", DateTime.Now.ToString("hh:mm:ss.fff"));
      Console.WriteLine("Sending data : " + sMsg);
      myHub.Invoke("Send", "Winform", sMsg).ContinueWith(task2 =>
      {
        if (task2.IsFaulted)
        {
          Console.WriteLine("An error occurred during the method call {0}", task2.Exception.GetBaseException());
        }
        else
        {
          Console.WriteLine("Successfully called MethodOnServer at {0}", DateTime.Now.ToString("hh:mm:ss.fff"));
        }
      });
      Thread.Sleep(60*1000);
    }

在本地网络上调用集线器方法很慢

本地网络配置错误。我的专业电脑正在使用自动配置脚本+自动检测连接参数,这减慢了一切。(=>愚蠢的浪费时间)

谢谢David的回答& &;关于使用Fiddler的建议(一切都很好,因为我发现Fiddler覆盖代理配置)