I have a program where the Arduino acts as an Ethernet Server.

The client continuously sends packets which is of the following format

Start Byte=0x7E;
Some Data/Command Bytes;      //Can be of varying length
End Byte=0x7A;

Some packets take more time to process than others.

So my question is what is the best way to read the bytes of the memory so that we always work on one packet at a time.I can read in data from the buffer one at a time and loop through till the END BYTE is reached but it doesn't seem a very efficient way to get the packets.

I would be interested if someone has better ideas on how to read in packets one at a time from the buffer in the most efficient way possible.

  • An important question would be if your can be sure that a packet contains exactly one message starting from the packet start - with TCP you almost certainly can't unless the sender is atypical, but with some other schemes you could. If you can't, you will likely either need to process messages character-by-character with a state machine that can pause and continue when another packet is received, or else copy from packet(s) to a message buffer, and be able to handle a message fragmented across packets, a packet that contains the end of one message and the start of another, etc. – Chris Stratton Jul 31 '14 at 16:21
  • can you elaborate on those schemes or point me in the right direction.Thanks. – SteveIrwin Aug 1 '14 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.