我正在使用SignalR使用SignalR.client动态链接库与一个网站进行对话。当客户端和站点在同一台机器上时,它可以完美地工作。(调用集线器方法是即时的)
但是,现在我通过网络在一台机器上设置了站点,调用(调用)平均需要2.5秒。(但要工作)
我在<1ms内对机器执行ping操作。
使用Wireshark时,我发现数据包在2.5秒后发送。
我调试了SignalR.client动态链接库,它停留在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聊天的例子来重现延迟。
pps:这是我的测试应用的(非常简单的)代码:
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);
}发布于 2013-03-04 21:23:17
问题是由错误的本地网络配置引起的。我的专业电脑使用的是自动配置脚本+自动检测连接参数,这减慢了一切。(=>愚蠢的浪费时间)
谢谢你,David,关于使用Fiddler的答案和建议(使用它一切都很好,因为我发现Fiddler覆盖了代理配置)
https://stackoverflow.com/questions/15198504
复制相似问题