Marfusios / websocket-client

🔧 .NET/C# websocket client library
MIT License
682 stars 126 forks source link

Calling WebSocketClient Start() or StartOrFail() takes > 2 seconds? #100

Closed LukeSawyers closed 2 years ago

LukeSawyers commented 2 years ago

Hi I'm experiencing some slower-than-Id-expect behavior when starting up the WebsocketClient class Using Setup:

_webSocket = new WebsocketClient(
    uri, () => new ClientWebSocket { Options = { KeepAliveInterval = TimeSpan.FromMilliseconds(50) } }
)
{
    IsReconnectionEnabled = true,
    ReconnectTimeout = TimeSpan.FromMilliseconds(100),
    ErrorReconnectTimeout = TimeSpan.FromMilliseconds(100)
};

And calling connecting code

public async Task ConnectAsync()
{
    try
    {
        var sw = Stopwatch.StartNew();
        await _webSocket.StartOrFail();
        sw.Stop();
    }
    catch (Exception ex)
    {
        _logger.Warn($"Error in {nameof(ConnectAsync)}", ex);
    }
}

sw.Elapsed will show ~2 sec depending on exact environment, that seems a little long, is there some way of reducing this / am I doing something wrong?

LukeSawyers commented 2 years ago

On testing with other socket clients, this seems to be more to do with the server side, please ignore this

PhantomGamers commented 1 year ago

Were the other socket clients you tested also based on ClientWebSocket ?

I'm currently running into this same issue, whereas in C++ with boost it connects significantly faster.