private void RestoreConnection(NetConnection connection, PausedConnectionResponse response) { Connection = connection; attemptingReconnection = false; Host = response.ReconnectHost; Port = response.ReconnectPort; failures = 0; DumpPendingOutgoing(); }
private void OnConnectionPaused(PausedConnectionResponse response) { if (IsSelectedPartitionDown()) { selectedEndpoint = ResolveAnyEndpoint().Result; Uri uri = new Uri(selectedEndpoint.Address); response.ReconnectHost = uri.Host; response.ReconnectPort = (ushort)uri.Port; } }
/// <summary> /// Handles lidgren connection close event (fires Closed event). /// </summary> public override void OnConnectionClose() { if (!gracefulClosing && !attemptingReconnection) { ConnectionInterrupted?.Invoke(); attemptingReconnection = true; PausedConnectionResponse response = new PausedConnectionResponse { ReconnectHost = Host, ReconnectPort = Port }; while (!gracefulClosing && failures < RetryAttempts) { response.FailedAttempts = failures; ConnectionPaused?.Invoke(response); if (response.Abort) { break; } NetConnection newConnection = Client.Connect(response.ReconnectHost, response.ReconnectPort); try { newConnection.WaitForConnectionToOpen(); RestoreConnection(newConnection, response); ConnectionRestored?.Invoke(); return; } catch (ConnectionOpenException) { failures++; } } ConnectionAborted?.Invoke(); AbortConnection(); } }