A series of reconnecting has failed
I'm testing reconnection of the websocket client. After receiving OnClose event, my program calls the following code to reconnect (not in the OnClose thread): websocket.Close(); websocket.Connect();
After about 10 failure and retries, I got exception "A series of reconnecting has failed". The websocket-sharp code does have the logic of _maxRetryCountForConnect=10. Anyone knows why this limitation is needed at all? And what is the best practice to reconnect except create a new WebSocket object?
I use below solutions in my application: use a timer to periodically check what is the last time to receive the message, if it is longer than a threshold, then call Close() and Connect(). However, if you don’t change the websocketsharp source code, you will easily reach the max retry count.
The discussion here indicate that the questioner evetually use dispose and create a new websocke instance. https://github.com/sta/websocket-sharp/issues/122
I have used this hack to get around the limitation temporarily but setting the maxCount too high will result in stack overflow
using System.Reflection;
[...]
var webSocketType = ws.GetType();
var maxRetryField = webSocketType.GetField("_maxRetryCountForConnect", BindingFlags.NonPublic | BindingFlags.Static);
if (maxRetryField != null)
maxRetryField.SetValue(ws, 100);