public void ProcessReceivedData(Pipe dataPipe, EndPoint remoteEndPoint, int maxPacketSize = 0, bool wait = true) { string remoteAddress = remoteEndPoint.ToString(); uint readedBytes = 0; UInt16 cmdId, dataType; UInt32 payloadSize, dataCount, param1, param2; byte[] payload = null; byte[] header = null; while (maxPacketSize == 0 || maxPacketSize >= (readedBytes + 16)) { if (!wait && dataPipe.AvailableBytes == 0) { return; } header = dataPipe.Read(16); //Pipe destroyed if (header.Length == 0) { return; } cmdId = header.ToUInt16(0); payloadSize = header.ToUInt16(2); dataType = header.ToUInt16(4); param1 = header.ToUInt32(8); param2 = header.ToUInt32(12); if (payloadSize == 0xFFFF) { payloadSize = dataPipe.Read(4).ToUInt32(); dataCount = dataPipe.Read(4).ToUInt32(); readedBytes += (payloadSize + 24); } else { dataCount = header.ToUInt16(6); readedBytes += (payloadSize + 16); } payload = dataPipe.Read(Convert.ToInt32(payloadSize)); HandleMessage(cmdId, dataType, ref payloadSize, ref dataCount, ref param1, ref param2, ref header, ref payload, ref remoteEndPoint); } }
public void ProcessReceivedData(Pipe dataPipe, EndPoint remoteEndPoint, int maxPacketSize = 0, bool wait = true) { string remoteAddress = remoteEndPoint.ToString(); uint readedBytes = 0; UInt16 cmdId, dataType; UInt32 payloadSize, dataCount, param1, param2; byte[] payload = null; byte[] header = null; while (maxPacketSize == 0 || maxPacketSize >= (readedBytes + 16)) { if (!wait && dataPipe.AvailableBytes == 0) return; header = dataPipe.Read(16); //Pipe destroyed if (header.Length == 0) return; cmdId = header.ToUInt16(0); payloadSize = header.ToUInt16(2); dataType = header.ToUInt16(4); param1 = header.ToUInt32(8); param2 = header.ToUInt32(12); if (payloadSize == 0xFFFF) { payloadSize = dataPipe.Read(4).ToUInt32(); dataCount = dataPipe.Read(4).ToUInt32(); readedBytes += (payloadSize + 24); } else { dataCount = header.ToUInt16(6); readedBytes += (payloadSize + 16); } payload = dataPipe.Read(Convert.ToInt32(payloadSize)); HandleMessage(cmdId, dataType, ref payloadSize, ref dataCount, ref param1, ref param2, ref header, ref payload, ref remoteEndPoint); } }