protected virtual void OnRecievedData(RecievedDataEventArgs e) { if (RecievedData != null) { RecievedData(this, e); } }
private byte[] RecieveUnencryptedData() { byte[] fullPackage; byte[] finalBytes = new byte[6]; byte[] recievedBytes = new byte[1024]; MemoryStream byteStream = new MemoryStream(); int bytesRead = 0; int timeoutTimer = 0; do { if (stream.DataAvailable) { timeoutTimer = 0; bytesRead = stream.Read(recievedBytes, 0, recievedBytes.Length); byteStream.Write(recievedBytes, 0, bytesRead); if (byteStream.Length > 6) { byteStream.Position -= 6; byteStream.Read(finalBytes, 0, 6); } } else { timeoutTimer += 1; Thread.Sleep(1); if (timeoutTimer > 10000) { return(new byte[0]); } } }while (!Enumerable.SequenceEqual(finalBytes, terminationBytes)); fullPackage = byteStream.ToArray(); if (fullPackage.Length > 6) { Array.Resize(ref fullPackage, fullPackage.Length - 6); } RecievedDataEventArgs e = new RecievedDataEventArgs(); e.byteData = fullPackage; OnRecievedData(e); return(fullPackage); }