© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
4 replies
UnemployedNinja

Specify timeout for websocket connection

I'm using Marfusios' websocket-client and I'm trying to specify a timeout period for establishing the connection, but I'm unsure how, or if it's even possible.

The GitHub demonstrates creating a factory for some client settings, but there are no options for specifying a timeout period
// Param: Func<ClientWebSocket>? clientFactory

var factory = new Func<ClientWebSocket>(() => new ClientWebSocket
{
    Options =
    {
        KeepAliveInterval = TimeSpan.FromSeconds(5),
        Proxy = ...
        ClientCertificates = ...
    }
});
var client = new WebsocketClient(url, factory);
// Param: Func<ClientWebSocket>? clientFactory

var factory = new Func<ClientWebSocket>(() => new ClientWebSocket
{
    Options =
    {
        KeepAliveInterval = TimeSpan.FromSeconds(5),
        Proxy = ...
        ClientCertificates = ...
    }
});
var client = new WebsocketClient(url, factory);


One client constructor gives the option for a
connectionFactory
connectionFactory
, where a cancelation token can be provided, but I'm unure how to use it (I'm still pretty fresh to C#):
Func<Uri, CancellationToken, Task<WebSocket>>? connectionFactory
Func<Uri, CancellationToken, Task<WebSocket>>? connectionFactory
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ SignalR Websocket Connection failed
C#CC# / help
4y ago
SignalR : Websocket connected twice on connection.
C#CC# / help
11mo ago
❔ Connection Timeout argument passed doesn't work for a SqlConnection
C#CC# / help
3y ago
How to check bandwidth of websocket connection?
C#CC# / help
3y ago