[英]SignalR stays in the Connecting state when IIS doesn't respond to connect request
在我的 Windows 10 機器上使用 SignalR 和 IIS 時遇到問題。 問題是IIS 只允許 10 個並發連接。 當達到第 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 不接受連接請求?
根據您的描述,建議您可以嘗試編寫代碼來監控連接時間,如果時間超過30秒,您可以直接停止連接到signlar服務器並顯示錯誤消息。
此外,IIS的連接限制只發生在windows10上。 如果您使用的是windows服務器,則IIS連接沒有限制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.