Advertisement
Guest User

adolf

a guest
Oct 12th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. public static void SendVoice(byte[] voice)
  2.         {
  3.             try
  4.             {
  5.                 byte[] sizeOfEncryptedPart;
  6.                 byte[] encryptedPart = Encoding.UTF8.GetBytes(Crypt.EncodeString($"{ch}voice{ch}{Server}{ch}{Login}{ch}"));
  7.                 byte[] voicePart = voice;
  8.  
  9.                 sizeOfEncryptedPart = new byte[] { Convert.ToByte(encryptedPart.Length) };
  10.  
  11.                 byte[] toSend = sizeOfEncryptedPart.Concat(encryptedPart).ToArray();
  12.                 toSend = sizeOfEncryptedPart.Concat(voicePart).ToArray();
  13.  
  14.                 udp.Send(toSend, data.Length, End);
  15.             }
  16.             catch (Exception e)
  17.             {
  18.                 MessageBox.Show(e.Message);
  19.             }
  20.         }
  21.  
  22.  
  23.         //Кусок кода сервера
  24.  
  25.         {
  26.             byte[] bytesContainsVoiceBytes = Net.Udp.Receive(ref Net.End); // Принимаем байты, содержащие байты с голосом
  27.  
  28.             byte encryptedPartLenght = bytesContainsVoiceBytes[0];
  29.  
  30.             byte[] encryptedPart = КастомнаяФункция(bytesContainsVoiceBytes, 1, encryptedPartLenght+1);
  31.             byte[] voicePart = КастомнаяФункция(bytesContainsVoiceBytes, encryptedPartLenght+1, bytesContainsVoiceBytes.Length);
  32.         }
  33.  
  34.         public static byte[] КастомнаяФункция(byte[] input, int startIndex, int endIndex)
  35.         {
  36.             List<byte> toReturn = new List<byte>();
  37.  
  38.             for (int i = 0; i < input.Length; i++)
  39.             {
  40.                 if (i >= startIndex && i <= endIndex)
  41.                 {
  42.                     toReturn.Add(input[i]);
  43.                 }
  44.             }
  45.  
  46.             return toReturn.ToArray();
  47.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement