diff --git a/Abstract/SocketClient.cs b/Abstract/SocketClient.cs index d81741b..2f082eb 100644 --- a/Abstract/SocketClient.cs +++ b/Abstract/SocketClient.cs @@ -27,6 +27,9 @@ namespace CommonSocketLibrary.Abstract _disposed = false; } + + public abstract Task Connect(); + protected async Task ConnectAsync(string url) { if (_socket != null) @@ -50,7 +53,7 @@ namespace CommonSocketLibrary.Abstract { if (_disposed || _socket == null || _cts == null) return; - + if (_socket.State == WebSocketState.Open) { _cts.CancelAfter(TimeSpan.FromMilliseconds(500)); @@ -114,7 +117,7 @@ namespace CommonSocketLibrary.Abstract } } - protected async Task Reconnect(IBackoff backoff, Action reconnect) + protected async Task Reconnect(IBackoff backoff) { while (true) { @@ -122,11 +125,11 @@ namespace CommonSocketLibrary.Abstract { TimeSpan delay = backoff.GetNextDelay(); await Task.Delay(delay); - reconnect.Invoke(); + await Connect(); backoff.Reset(); break; } - catch (Exception) + catch { _logger.Error("Unable to reconnect to server."); } diff --git a/Common/WebSocketClient.cs b/Common/WebSocketClient.cs index 2fe6ddf..f1f2e6a 100644 --- a/Common/WebSocketClient.cs +++ b/Common/WebSocketClient.cs @@ -6,7 +6,7 @@ using Serilog; namespace CommonSocketLibrary.Common { - public class WebSocketClient : SocketClient + public abstract class WebSocketClient : SocketClient { protected IDictionary _handlers; private readonly MessageTypeManager _messageTypeManager;