/// <summary> /// Reconnect WebSocket connection in case of failures /// </summary> private void Reconnect() { if (IsConnected) { _ws.Close(true); } if (_retryCount > _retries) { _ws.Close(true); DisableReconnect(); OnNoReconnect?.Invoke(); } else { OnReconnect?.Invoke(); _retryCount += 1; _ws.Close(true); Connect(); _timerTick = (int)Math.Min(Math.Pow(2, _retryCount) * _interval, 60); if (_debug) { Console.WriteLine("New interval " + _timerTick); } _timer.Start(); } }
public void Poll() { if (!IsListening) { _udpListenTask = null; } lock (_newConnectionQueue) { while (_newConnectionQueue.Count > 0) { int connectionId = _newConnectionQueue.Dequeue(); string username = _usernamesQueue.Dequeue(); OnNewConnection?.Invoke(connectionId, username); } } lock (_reconnectQueue) { while (_reconnectQueue.Count > 0) { int connectionId = _reconnectQueue.Dequeue(); OnReconnect?.Invoke(connectionId); } } lock (_disconnectQueue) { while (_disconnectQueue.Count > 0) { int connectionId = _disconnectQueue.Dequeue(); OnDisconnect?.Invoke(connectionId); } } lock (_receiveIdQueue) { while (_receiveIdQueue.Count > 0) { int connectionId = _receiveIdQueue.Dequeue(); if (_receiveDataQueue.Count > 0) { byte[] data = _receiveDataQueue.Dequeue(); OnDataReceived?.Invoke(connectionId, data); } else { LogManager.RuntimeLogger.LogError("Network error! Data queue is empty!"); } } } }
/// <summary> /// Reconnect WebSocket connection in case of failures /// </summary> private void Reconnect() { if (IsConnected) { _ws.Close(true); } if (_retryCount > _retries) { _ws.Close(true); DisableReconnect(); OnNoReconnect?.Invoke(); } else { OnReconnect?.Invoke(); _retryCount += 1; _ws.Close(true); Connect(); _timerTick = _interval; _timer.Start(); } }
/// <summary> /// Management reconnect /// </summary> /// <param name="account">Connected account</param> #region OnReconnectHandler private void OnReconnectHandler(TAccount account) { var forceReconnect = false; while (true) { // If enable auto reconnect and try count greater than zero - try for reconnect // If try count equal zero or auto reconnect is disable if (!Configuration.AutoReconnect || _reconnectTryCount <= 0) { // Check flag use unable to connect is false if (!_unableToConnectFlag) { _unableToConnectFlag = true; _reconnectModeEnable = false; OnUnableToConnectHandler(); } break; } // else try for reconnect // If reconnect enable And forceReconnect is false => reject reconnect request if (_reconnectModeEnable && !forceReconnect) { break; } // If game playing is false (For unity) => reject reconnect request #if UNITY_2018_1_OR_NEWER if (!G9SuperNetCoreClient4Unity.GameIsPlaying) { break; } #endif // Set reconnect mode true _reconnectModeEnable = true; // Call reconnect event OnReconnect?.Invoke(account, _reconnectTryCount); // Check first time or no => set delay for try reconnect if (Configuration.ReconnectTryCount == _reconnectTryCount) { // if first time => 30% of duration for try to reconnect Thread.Sleep((ushort)(Configuration.ReconnectDuration * 0.3)); } else { // In other time => full duration for try to reconnect Thread.Sleep(Configuration.ReconnectDuration); } // Minus try reconnect _reconnectTryCount--; // Reconnect again var restart = StartConnection(); if (restart.Wait(Configuration.ReconnectDuration) && restart.Result) { _reconnectModeEnable = false; break; } forceReconnect = true; } }
public void RaiseOnReconnect() { OnReconnect?.Invoke(); }
protected void Reconnect() { OnReconnect?.Invoke(this); }
private void GotifySharp_OnReconnect(object sender, WebsocketReconnectStatus e) { OnReconnect?.Invoke(this, e); }
protected virtual void DoOnReconnect() { OnReconnect?.Invoke(this, EventArgs.Empty); }
private void Stream_OnReconnect(object sender, WebsocketReconnectStatus e) { OnReconnect?.Invoke(this, e); }
public void InvokeReconnect() { OnReconnect?.Invoke(""); }
private void Ws_OnOpen(ReconnectionInfo reconnectionInfo) { var test = reconnectionInfo.Type; OnReconnect?.Invoke(this, (WebsocketReconnectStatus)reconnectionInfo.Type); }