diff --git a/client/Assets/Vanguard/Runtime/Battle/GameConnection.cs b/client/Assets/Vanguard/Runtime/Battle/GameConnection.cs index 50c510c..7873818 100644 --- a/client/Assets/Vanguard/Runtime/Battle/GameConnection.cs +++ b/client/Assets/Vanguard/Runtime/Battle/GameConnection.cs @@ -224,7 +224,7 @@ namespace Vanguard.Battle break; case ServerPing ping: - _ = SendAsync(new ClientPong { Nonce = ping.Nonce }, cancellationToken); + _ = SendPongAsync(ping.Nonce, cancellationToken); break; case ServerPong _: @@ -238,9 +238,20 @@ namespace Vanguard.Battle } } - private async Task PingLoopAsync(CancellationToken cancellationToken) + private async Task SendPongAsync(long nonce, CancellationToken cancellationToken) { try + { + await SendAsync(new ClientPong { Nonce = nonce }, cancellationToken); + } + catch (Exception) + { + // соединение уже закрывается + } + } + + private async Task PingLoopAsync(CancellationToken cancellationToken) + { try { while (!cancellationToken.IsCancellationRequested && IsConnected) {