Signalr Client Timeout RRS feed

  • Question

  • User718448626 posted

    I have a console app that connects to a local ASP.NET Core 2.1 server with SignalR.  My question is, how do I get the client to disconnect or attempt to connect when the server is not running.  When there is a http running on the server without SignalR then the connection timeout quickly.  What parameter can I use so that the client can end attempt to connect when the server is not running.  Thank you.

    hubConnection = new HubConnectionBuilder()
                   .WithUrl("", options=> {
                       options.Transports = HttpTransportType.WebSockets;
    Thursday, December 20, 2018 12:40 AM

All replies

  • User61956409 posted

    Hi Albertk89,

    Normally after connectivity between client and server is lost, the client tries to reconnect and the server waits for the client to reconnect. And SignalR connection would be ended once the attempts to reconnect are unsuccessful and the disconnect timeout period ends. This mechanism could help client reconnect to hub server without starting a new connection.

    If you want to improve user experience of your application while connection(s)/communications between client and server have some problems, you can try to put your key code snippet in try-catch block and show user notice message if any exceptions occur.

        connection = new HubConnectionBuilder()
        await connection.StartAsync();
        //other code logic here
    catch (Exception ex)
        Console.WriteLine("Can not communicate with server now, please try later.");

    Besides, if possible, please not explicitly Transports, let SignalR itself choose and use appropriate transports to make its connections.

    With Regards,

    Fei Han

    Friday, December 21, 2018 3:28 AM
  • User718448626 posted

    Yes, I have similar code.  But try with a Uri that does not have any server running, it takes about a minute to timeout.

    Can you confirm that if FQDN is used then the timeout for non existence server is quick but alternatively if IP is used it would take substantial amount of time for timeout to occur.  Thank you.

    Friday, December 21, 2018 3:38 AM