internal void SendPing() { ulong unixTimeStamp = (ulong)(DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks); byte[] timeBytes = BitConverter.GetBytes(unixTimeStamp); var dgram = new byte[9]; timeBytes.CopyTo(dgram, 1); dgram[0] = (1 << 5); var encryptedData = _cryptState.Encrypt(dgram, timeBytes.Length + 1); if (!_isConnected) { Debug.LogError("Not yet connected"); return; } if (!_useTcp && _numPingsOutstanding >= MumbleConstants.MAX_CONSECUTIVE_MISSED_UDP_PINGS) { Debug.LogWarning("Error establishing UDP connection, will switch to TCP"); _useTcp = true; } //Debug.Log(_numPingsSent - _numPingsReceived); _numPingsOutstanding++; lock (_udpClient) { _udpClient.Send(encryptedData, encryptedData.Length); } }
internal void SendPing() { ulong unixTimeStamp = (ulong)(DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks); byte[] timeBytes = BitConverter.GetBytes(unixTimeStamp); var dgram = new byte[9]; timeBytes.CopyTo(dgram, 1); dgram[0] = (1 << 5); var encryptedData = _cryptState.Encrypt(dgram, timeBytes.Length + 1); if (!_isConnected) { Debug.LogError("Not yet connected"); return; } while (_isSending) { System.Threading.Thread.Sleep(1); } _isSending = true; if (!_useTcp && _numPingsSent - _numPingsReceived >= MumbleConstants.MAX_MISSED_UDP_PINGS) { Debug.LogWarning("Error establishing UDP connection, will switch to TCP"); _useTcp = true; } //Debug.Log(_numPingsSent - _numPingsReceived); _numPingsSent++; _udpClient.BeginSend(encryptedData, encryptedData.Length, new AsyncCallback(OnSent), null); }