Skip to content

How should we set ClientWebSocket options? #8

@kblok

Description

@kblok

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions