void receive() { EndPoint dummyEndpoint = new IPEndPoint(IPAddress.Any, 0); ReedSolomon rs = new ReedSolomon(); //check error bits int encodelength = 1472; //Byteencodelength byte[] _encode = new byte[encodelength]; { int dataleng = rs.GetDataLeng(encodelength); int[] dataInt = new int[dataleng / 4]; //initialize for (int i = 0; i < dataInt.Length; i++) { dataInt[i] = i; } byte[] datarand = new byte[dataInt.Length * sizeof(int)]; Buffer.BlockCopy(dataInt, 0, datarand, 0, datarand.Length); rs.encode(datarand, _encode); } int Frame = 0, error = 0, lost = 0; int maxError = 0, minError = 100000; while (true) { try { int length = socket.ReceiveFrom(receiveBuffer, ref dummyEndpoint); Frame++; int res = checkBitDiff(_encode, receiveBuffer, length); maxError = (res > maxError) ? res : maxError; minError = (res < minError) ? res : minError; int decodedataleng = rs.GetDataLeng(length); byte[] decodedata = new byte[decodedataleng]; int sign = rs.decode(receiveBuffer, length, decodedata); if (sign == 0) //can't correct { error++; } else { int[] data = new int[decodedata.Length / 4]; Buffer.BlockCopy(decodedata, 0, data, 0, decodedata.Length); //check equal for (int i = 1; i < data.Length; i++) { if (data[i] != i) { error++; break; } } //check order //int order = BitConverter.ToInt32(decodedata, 0); //if(order > Frame) { // lost += order - Frame - 1; // Frame = order; //} } } catch (Exception ex) { //Console.WriteLine(ex); } if ((Frame % 100 == 0) && (Frame > 0)) { Console.WriteLine("Frame {0} . Error: {1} . Error bit: Max {2}, Min: {3}", Frame, error, maxError, minError); } } }