IEnumerator DoPingAsync() { // How long to run the ping var pingSeconds = m_HeadlessRunTimeMs / 1000f; Debug.Log($"Pinging remote server for {pingSeconds} seconds..."); // Start new ping client var udpPinger = new UdpPingWrapper(); var timer = Stopwatch.StartNew(); try { udpPinger.Start(m_CustomIp); while (timer.ElapsedMilliseconds < m_HeadlessRunTimeMs) { udpPinger.Update(); yield return(null); } // Dump ping stats before we dispose of the client Debug.Log(udpPinger.GetStats()); } finally { udpPinger.Dispose(); } }
// Start is called before the first frame update void StartNewPingClient() { if (string.IsNullOrEmpty(m_PingServerEndpoint)) { Debug.LogWarning("Cannot start pinging - No ping server endpoint was entered"); return; } if (m_UdpPing != null) { Debug.LogWarning("Cannot start pinging - Pinging already in progress"); return; } Debug.Log("Starting pinging..."); try { m_UdpPing = new UdpPingWrapper(); m_UdpPing.Start(m_PingServerEndpoint); m_State = MatchmakingState.ServerPing; } catch (Exception e) { Debug.LogError("Cannot start pinging due to exception - " + e.Message); m_UdpPing?.Dispose(); m_UdpPing = null; } }