Reputation: 1833
I use ClientWebSocket to connect to a socket server. If I stop the server I got WebSocketException what is OK. Then I try to reconnect.
If I use
await wsClient.ConnectAsync(serviceUri, cts.Token);
I get "System.InvalidOperationException: 'The WebSocket has already been started.'"
If I try to close it before reconnecting by
await wsClient.CloseAsync(WebSocketCloseStatus.Empty, string.Empty, CancellationToken.None);
I get "System.Net.WebSockets.WebSocketException: 'The WebSocket is in an invalid state ('Aborted') for this operation. Valid states are: 'Open, CloseReceived, CloseSent'' "
So what is the proper way of reconnecting after the connection has been lost.
Upvotes: 4
Views: 3230