【问题标题】:SignalR stays in the Connecting state when IIS doesn't respond to connect request当 IIS 未响应连接请求时 SignalR 保持连接状态
【发布时间】:2020-01-08 07:42:03
【问题描述】:

在我的 Windows 10 机器上使用 SignalR 和 IIS 时遇到问题。问题是IIS only allows for 10 concurrent connections。当第 10 个连接到达时,客户端 HubConnection 会长时间处于 Connecting 状态。

using Microsoft.AspNet.SignalR.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {

        static int usedConnections = 0;

        static  void Main(string[] args)
        {
            Foo();

            while (true) { }
        }


        static async void Foo()
        {
            for(int i = 0; i < 15; i++)
            {
                await SetupSignalR();
            }
        }

        static async Task SetupSignalR()
        {
            //Set connection
            var hub = new HubConnection("http://MyComputer/MyIISApp");

            hub.TraceLevel = TraceLevels.All;
            hub.TraceWriter = Console.Out;

            //Make proxy to hub based on hub name on server
            var myHub = hub.CreateHubProxy("MyIISHub");
            //Start connection
            hub.TransportConnectTimeout = TimeSpan.FromSeconds(5);

            await hub.Start();
            usedConnections++;
            Console.WriteLine($"Used Conenctions: {usedConnections}");

            return;
        }
    }
}

经过一段合理的时间后,我想向用户显示 HubConnection 无法连接到服务器的消息,但我不知道如何设置超时或触发事件。如何通知用户 IIS 不接受连接请求?

【问题讨论】:

标签: c# asp.net iis signalr


【解决方案1】:

根据你的描述,我建议你可以尝试编写代码来监控连接时间,如果时间超过了30秒,你可以直接停止连接signlar服务器并显示错误信息。

此外,IIS 的连接限制只发生在 windows10 上。如果您使用的是 windows 服务器,则 IIS 连接没有限制。

【讨论】:

  • 那么现在有办法为 hub.Start() 设置超时吗?
  • 关于Windows Server没有这个限制;该应用程序在开发过程中有时会在 Windows 10 机器上运行,我想知道何时达到连接限制。今天,当达到此限制时,我的应用程序就会冻结。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-10
  • 2013-06-28
  • 1970-01-01
相关资源
最近更新 更多