john_9559
john_9559

Reputation: 51

Setting the ping interval on the SignalR .NET Client

I've set up a signalr API endpoint (WS only) with the following configuration:

                .AddHubOptions<MyHub>(options =>
                {
                    options.ClientTimeoutInterval = TimeSpan.FromSeconds(120);
                    options.KeepAliveInterval = TimeSpan.FromSeconds(60);
                })

Now, the .net client application pings the endpoint every ~15 seconds and gets closed after few tries. How to configure the .net client to ping the server every 60 seconds? I've checked the following code, but it didn't help:

                .WithUrl("signalrendpointaddress", options =>
                {
                    options.CloseTimeout = TimeSpan.FromSeconds(120);
                    options.WebSocketConfiguration = (configuration) => { configuration.KeepAliveInterval = TimeSpan.FromSeconds(60); };
                })

client pings the server and disconnects

Upvotes: 1

Views: 1300

Answers (1)

Yiyi You
Yiyi You

Reputation: 18169

If you want to change KeepAliveInterval to 60 seconds,you need to change serverTimeoutInMilliseconds.

var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();
connection.serverTimeoutInMilliseconds = 2 * 60 * 1000;

serverTimeoutInMilliseconds:

The server timeout in milliseconds. If this timeout elapses without receiving any messages from the server, the connection will be terminated with an error. The default timeout value is 30,000 milliseconds (30 seconds).

For more details,you can refer to the official doc.

Upvotes: 1

Related Questions