private static bool AttemptReconnect()
            {
                if (attemptingReconnect)
                {
                    return(false);
                }
                if (webSocket.IsAlive)    // no reconnect needed
                {
                    return(true);
                }
                attemptingReconnect = true;
                var sleep = connectionEstablished ? 10 + random.Next(0, 20) : 0;

                Helpers.ConsolePrint("SOCKET", "Attempting reconnect in " + sleep + " seconds");
                if (connectionEstablished)    // Don't wait if no connection yet
                // Don't not wait again
                {
                    connectionEstablished = true;
                    Thread.Sleep(sleep * 1000);
                }
                for (int i = 0; i < 5; i++)
                {
                    webSocket.Connect();
                    Thread.Sleep(100);
                    if (webSocket.IsAlive)
                    {
                        attemptingReconnect = false;
                        return(true);
                    }
                    Thread.Sleep(1000);
                }
                attemptingReconnect = false;
                OnConnectionLost.Emit(null, EventArgs.Empty);
                return(false);
            }
 private static bool AttemptReconnect()
 {
     if (attemptingReconnect)
     {
         return(false);
     }
     if (webSocket.IsAlive)    // no reconnect needed
     {
         return(true);
     }
     attemptingReconnect = true;
     Helpers.ConsolePrint("SOCKET", "Attempting reconnect");
     for (int i = 0; i < 5; i++)
     {
         webSocket.Connect();
         Thread.Sleep(100);
         if (webSocket.IsAlive)
         {
             attemptingReconnect = false;
             return(true);
         }
         Thread.Sleep(1000);
     }
     attemptingReconnect = false;
     OnConnectionLost.Emit(null, EventArgs.Empty);
     return(false);
 }
Example #3
0
            private static bool AttemptReconnect()
            {
                if (_attemptingReconnect)
                {
                    return(false);
                }
                if (_webSocket.IsAlive)
                {
                    // no reconnect needed
                    return(true);
                }
                _attemptingReconnect = true;
                var sleep = _connectionEstablished ? 10 + Random.Next(0, 20) : 0;

                Helpers.ConsolePrint("SOCKET", "Attempting reconnect in " + sleep + " seconds");
                // More retries on first attempt
                var retries = _connectionEstablished ? 5 : 25;

                if (_connectionEstablished)
                {
                    // Don't wait if no connection yet
                    Thread.Sleep(sleep * 1000);
                }
                else
                {
                    // Don't not wait again
                    _connectionEstablished = true;
                }
                for (var i = 0; i < retries; i++)
                {
                    _webSocket.Connect();
                    Thread.Sleep(100);
                    if (_webSocket.IsAlive)
                    {
                        _attemptingReconnect = false;
                        return(true);
                    }
                    Thread.Sleep(1000);
                }
                _attemptingReconnect = false;
                OnConnectionLost.Emit(null, EventArgs.Empty);
                return(false);
            }
Example #4
0
 private static void ConnectionLost(object state)
 {
     Helpers.ConsolePrint("SOCKET", "ConnectionLost");
     OnConnectionLost.Emit(null, EventArgs.Empty);
 }