private void TcpConnectionClosed(TcpPackageConnection connection) { if (_state == ConnectionState.Init) { throw new Exception(); } if (_state == ConnectionState.Closed || _connection != connection) { LogDebug("IGNORED (_state: {0}, _conn.ID: {1:B}, conn.ID: {2:B}): TCP connection to [{3}, L{4}] closed.", _state, _connection == null ? Guid.Empty : _connection.ConnectionId, connection.ConnectionId, connection.RemoteEndPoint, connection.LocalEndPoint); return; } _state = ConnectionState.Connecting; _connectingPhase = ConnectingPhase.Reconnecting; LogDebug("TCP connection to [{0}, L{1}, {2:B}] closed.", connection.RemoteEndPoint, connection.LocalEndPoint, connection.ConnectionId); _subscriptions.PurgeSubscribedAndDroppedSubscriptions(_connection.ConnectionId); _reconnInfo = new ReconnectionInfo(_reconnInfo.ReconnectionAttempt, _stopwatch.Elapsed); if (Interlocked.CompareExchange(ref _wasConnected, 0, 1) == 1) { RaiseDisconnected(connection.RemoteEndPoint); } }
private void TimerTick() { switch (_state) { case ConnectionState.Init: break; case ConnectionState.Connecting: { if (_connectingPhase == ConnectingPhase.Reconnecting && _stopwatch.Elapsed - _reconnInfo.TimeStamp >= _settings.ReconnectionDelay) { LogDebug("TimerTick checking reconnection..."); _reconnInfo = new ReconnectionInfo(_reconnInfo.ReconnectionAttempt + 1, _stopwatch.Elapsed); if (_settings.MaxReconnections >= 0 && _reconnInfo.ReconnectionAttempt > _settings.MaxReconnections) { CloseConnection("Reconnection limit reached."); } else { RaiseReconnecting(); DiscoverEndPoint(null); } } if (_connectingPhase == ConnectingPhase.Authentication && _stopwatch.Elapsed - _authInfo.TimeStamp >= _settings.OperationTimeout) { RaiseAuthenticationFailed("Authentication timed out."); GoToConnectedState(); } if (_connectingPhase > ConnectingPhase.ConnectionEstablishing) { ManageHeartbeats(); } break; } case ConnectionState.Connected: { // operations timeouts are checked only if connection is established and check period time passed if (_stopwatch.Elapsed - _lastTimeoutsTimeStamp >= _settings.OperationTimeoutCheckPeriod) { // On mono even impossible connection first says that it is established // so clearing of reconnection count on ConnectionEstablished event causes infinite reconnections. // So we reset reconnection count to zero on each timeout check period when connection is established _reconnInfo = new ReconnectionInfo(0, _stopwatch.Elapsed); _operations.CheckTimeoutsAndRetry(_connection); _subscriptions.CheckTimeoutsAndRetry(_connection); _lastTimeoutsTimeStamp = _stopwatch.Elapsed; } ManageHeartbeats(); break; } case ConnectionState.Closed: break; default: throw new Exception(string.Format("Unknown state: {0}.", _state)); } }
private async Task OnReconnect(ReconnectionInfo reconnectionInfo) { // we do not want to pass "initial" if (reconnectionInfo.Type == ReconnectionType.Initial) { return; } _clientLogger.Log($"Reconnection happened, type: {reconnectionInfo.Type}"); await _clientListener.OnReconnected(); }
private void TimerTick() { switch (_state) { case ConnectionState.Init: break; case ConnectionState.Connecting: { if (_connectingPhase == ConnectingPhase.Reconnecting && _stopwatch.Elapsed - _reconnInfo.TimeStamp >= _settings.ReconnectionDelay) { LogDebug("TimerTick checking reconnection..."); _reconnInfo = new ReconnectionInfo(_reconnInfo.ReconnectionAttempt + 1, _stopwatch.Elapsed); if (_settings.MaxReconnections >= 0 && _reconnInfo.ReconnectionAttempt > _settings.MaxReconnections) CloseConnection("Reconnection limit reached."); else { RaiseReconnecting(); DiscoverEndPoint(null); } } if (_connectingPhase == ConnectingPhase.Authentication && _stopwatch.Elapsed - _authInfo.TimeStamp >= _settings.OperationTimeout) { RaiseAuthenticationFailed("Authentication timed out."); GoToConnectedState(); } if (_connectingPhase > ConnectingPhase.ConnectionEstablishing) ManageHeartbeats(); break; } case ConnectionState.Connected: { // operations timeouts are checked only if connection is established and check period time passed if (_stopwatch.Elapsed - _lastTimeoutsTimeStamp >= _settings.OperationTimeoutCheckPeriod) { // On mono even impossible connection first says that it is established // so clearing of reconnection count on ConnectionEstablished event causes infinite reconnections. // So we reset reconnection count to zero on each timeout check period when connection is established _reconnInfo = new ReconnectionInfo(0, _stopwatch.Elapsed); _operations.CheckTimeoutsAndRetry(_connection); _subscriptions.CheckTimeoutsAndRetry(_connection); _lastTimeoutsTimeStamp = _stopwatch.Elapsed; } ManageHeartbeats(); break; } case ConnectionState.Closed: break; default: throw new Exception(string.Format("Unknown state: {0}.", _state)); } }
private void TcpConnectionClosed(TcpPackageConnection connection) { if (_state == ConnectionState.Init) throw new Exception(); if (_state == ConnectionState.Closed || _connection != connection) { LogDebug("IGNORED (_state: {0}, _conn.ID: {1:B}, conn.ID: {2:B}): TCP connection to [{3}, L{4}] closed.", _state, _connection == null ? Guid.Empty : _connection.ConnectionId, connection.ConnectionId, connection.RemoteEndPoint, connection.LocalEndPoint); return; } _state = ConnectionState.Connecting; _connectingPhase = ConnectingPhase.Reconnecting; LogDebug("TCP connection to [{0}, L{1}, {2:B}] closed.", connection.RemoteEndPoint, connection.LocalEndPoint, connection.ConnectionId); _subscriptions.PurgeSubscribedAndDroppedSubscriptions(_connection.ConnectionId); _reconnInfo = new ReconnectionInfo(_reconnInfo.ReconnectionAttempt, _stopwatch.Elapsed); if (Interlocked.CompareExchange(ref _wasConnected, 0, 1) == 1) { RaiseDisconnected(connection.RemoteEndPoint); } }
private void HandleDiscordWebSocketReconnection(ReconnectionInfo reconnectionInfo) { ApplicationManager.Instance.MainViewModel.AppSettingsViewModel.UpdateDiscordWebSocketState(reconnectionInfo .Type); DiscordBotLogin(); }
private void TimerTick() { switch (_state) { case ConnectionState.Init: break; case ConnectionState.Connecting: { if (_connectingPhase == ConnectingPhase.Reconnecting && _stopwatch.Elapsed - _reconnInfo.TimeStamp >= _settings.ReconnectionDelay) { LogDebug("TimerTick checking reconnection..."); _reconnInfo = new ReconnectionInfo(_reconnInfo.ReconnectionAttempt + 1, _stopwatch.Elapsed); if (_settings.MaxReconnections >= 0 && _reconnInfo.ReconnectionAttempt > _settings.MaxReconnections) { CloseConnection("Reconnection limit reached."); } else { RaiseReconnecting(); _operations.CheckTimeoutsAndRetry(_connection); _subscriptions.CheckTimeoutsAndRetry(_connection); DiscoverEndPoint(null); } } if (_connectingPhase == ConnectingPhase.Authentication && _stopwatch.Elapsed - _authInfo.TimeStamp >= _settings.OperationTimeout) { RaiseAuthenticationFailed("Authentication timed out."); GoToIdentifyState(); } if (_connectingPhase == ConnectingPhase.Identification && _stopwatch.Elapsed - _identifyInfo.TimeStamp >= _settings.OperationTimeout) { const string msg = "Timed out waiting for client to be identified"; LogDebug(msg); CloseTcpConnection(msg); } if (_connectingPhase > ConnectingPhase.ConnectionEstablishing) { ManageHeartbeats(); } break; } case ConnectionState.Connected: { // operations timeouts are checked only if connection is established and check period time passed if (_stopwatch.Elapsed - _lastTimeoutsTimeStamp >= _settings.OperationTimeoutCheckPeriod) { _operations.CheckTimeoutsAndRetry(_connection); _subscriptions.CheckTimeoutsAndRetry(_connection); _lastTimeoutsTimeStamp = _stopwatch.Elapsed; } ManageHeartbeats(); break; } case ConnectionState.Closed: break; default: throw new Exception(string.Format("Unknown state: {0}.", _state)); } }
private void ReconnectHandler(ReconnectionInfo info) { Console.WriteLine($"Reconnection happened, type: {info.Type}"); }
private void OnReconnection(ReconnectionInfo info) { _logger.LogInformation($"'{info.Type}' reconnection event occured"); _connection.OnNext( new ConnectionInfo(Result.FromSuccess <ConnectionState, Exception>(ConnectionState.Connected))); }
public ReconnectedEventArgs(ReconnectionInfo info) { Info = info; }
private void WsConnected(ReconnectionInfo inf) { _logger.Information("Connected to Jackbox games services."); }
internal void InvokeReconnected(Client client, ReconnectionInfo info) { Reconnected?.Invoke(client, new ReconnectedEventArgs(info)); }
private static void OnReconnect(ReconnectionInfo info) { Console.WriteLine($"Reconnection happened, type: {info.Type}"); }
private void WebsocketReconnectionHappened(ReconnectionInfo info) { _settings.Controller.WriteTextToLCDSecondLine("UI24R is reconnected", 5); }
private void Ws_OnOpen(ReconnectionInfo reconnectionInfo) { var test = reconnectionInfo.Type; OnReconnect?.Invoke(this, (WebsocketReconnectStatus)reconnectionInfo.Type); }