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
c#
// Param: Func<ClientWebSocket>? clientFactory

var factory = new Func<ClientWebSocket>(() => new ClientWebSocket
{
Options =
{
KeepAliveInterval = TimeSpan.FromSeconds(5),
Proxy = ...
ClientCertificates = ...
}
});
var client = new WebsocketClient(url, factory);
c#
// 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, where a cancelation token can be provided, but I'm unure how to use it (I'm still pretty fresh to C#):
c#
Func<Uri, CancellationToken, Task<WebSocket>>? connectionFactory
c#
Func<Uri, CancellationToken, Task<WebSocket>>? connectionFactory
3 Replies
UnemployedNinja
UnemployedNinja3mo ago
bump
Lex Li
Lex Li3mo ago
1. Skip WebSockets libraries and use SignalR if you can. 2. There are too many WebSockets libraries out there, so just pick up one that has rich documentation.
UnemployedNinja
UnemployedNinja3mo ago
Yea, I noticed there are quite a few. Websocket.Client had the most downloads (2m+) so I just went with that one I’ll look at SignalR though
Want results from more Discord servers?
Add your server
More Posts