void FrmMain_Receive(object sender, byte[] e)
{
byte[] newBytes = new byte[e.Length - 20];
Buffer.BlockCopy(builtPacket, 20, newBytes, 0, newBytes.Length);
e = newBytes;
int x = 0;
var udpHeader = UdpHeader.Create(e, ref x);
newBytes = new byte[e.Length - 8];
Buffer.BlockCopy(e, 8, newBytes, 0, newBytes.Length);
e = newBytes;
if (udpHeader.SourcePort != 9959)
{
return;
}
lbTamanho.Invoke(new Action(() =>
{
txtConteudo.Clear();
lbTamanho.Text = e.Length.ToString();
lbCrc.Text = udpHeader.Checksum.ToString();
txtConteudo.Text += "Valor recebido: ";
txtConteudo.Text += Encoding.Default.GetString(e, 1, e.Length - 1 - e[0]);
txtConteudo.Text += Environment.NewLine;
byte ecBytes = e[0];
txtConteudo.Text += "Bytes de correção: " + ecBytes;
txtConteudo.Text += Environment.NewLine;
int[] realPayloadInt = e.Select(d => (int)d).ToArray();
ReedSolomonDecoder decoder = new ReedSolomonDecoder(GenericGf.QrCodeField256);
if (decoder.Decode(realPayloadInt, ecBytes))
{
byte[] data = realPayloadInt.Select(d => (byte)d).ToArray();
byte[] message = new byte[data.Length - 1 - ecBytes];
Buffer.BlockCopy(data, 1, message, 0, message.Length);
txtConteudo.Text += "Mensagem decodificada: ";
txtConteudo.Text += Encoding.Default.GetString(message);
}
else
{
txtConteudo.Text += "Não foi possivel recuperar a mensagem original";
}
}));
}