Q-bertsuit
Q-bertsuit

Reputation: 3437

SignalR stays in the Connecting state when IIS doesn't respond to connect request

I'm having an issue when using SignalR and IIS on my Windows 10 machine. The problem is that IIS only allows for 10 concurrent connections. When The 10th connection is reached, the client side HubConnection will stay in the Connecting state for a long time.

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;
        }
    }
}

After a reasonable period of time I would like to display a message to the user that the HubConnection is unable to connect to the server, but I cant figure out how to either set a timeout or trigger an event. What can I do to notify the user that IIS isn't accepting the connection request?

Upvotes: 0

Views: 1059

Answers (1)

Brando Zhang
Brando Zhang

Reputation: 28192

According to your description, I suggest you could try to write the codes to monitor the connection time, if the time has exceed the 30 seconds, you could directly stop connect to the signlar server and show a error message.

Besides, the connection limit for the IIS is only happened on the windows10. If you used the windows server, there is no limit for the IIS connection.

Upvotes: 0

Related Questions