Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should we set ClientWebSocket options? #8

Open
kblok opened this issue Jan 21, 2019 · 1 comment
Open

How should we set ClientWebSocket options? #8

kblok opened this issue Jan 21, 2019 · 1 comment

Comments

@kblok
Copy link

kblok commented Jan 21, 2019

I bet CreateClientWebSocket returns a WebSocket because both Managed.ClientWebSocket and ClientWebSocket inherits from WebSocket.

The problem is that it hides the Options property. If I want to set the KeepAliveInterval should I do something like this?

var client = SystemClientWebSocket.CreateClientWebSocket();
if (client is System.Net.WebSockets.Managed.ClientWebSocket managed)
{
    managed.Options.KeepAliveInterval = TimeSpan.FromSeconds(0);
    await managed.ConnectAsync(uri, cancellationToken);
}
else
{
    var coreSocket = client as ClientWebSocket;
    coreSocket.Options.KeepAliveInterval = TimeSpan.FromSeconds(0);
    await coreSocket.ConnectAsync(uri, cancellationToken);
}

If think one option would be passing the Options as an argument to the ConnectAsync method.

@martonb
Copy link

martonb commented Apr 1, 2022

Alternatively, a helper function in the form of SystemClientWebSocket.SetKeepAliveInterval(WebSocket ws, TimeSpan interval) would be helpful too...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants