Breaking a stream of bits up into messages may seem like a
simple task, but it is complicated by the presence of errors.
One simple (but insufficient) approach would be to begin
each message with a field that indicate how many bits
(or bytes) were contained in the entire message.
Unfortunately, if any of the bits in the message length
field get damaged, the receiver will have no way of
getting back into synchronization so that it can correctly
identify the length fields of subsequent packages.
A more popular technique is to begin and end each packet with
a special sequence of bits that is used to indicate the begin
(or end) of a packet.
If one of these sequences gets damaged, the receiver
might miss one packet, but would get back in synch on
the following packet.
Since much data sent on the network can contain odd segments
of binary data, there is a risk that one of these special
start/end sequences might appear in the midst of a message
as data.
This possibility can be addressed by techniques known
as byte stuffing. For example:
The ASCII character set includes two special
codes associated with characters names
STX (start transmission) and ETX (end transmission).
These are intended to be used to indicate the
start and end of a message.
ASCII also contains another character named DLE
(data link escape).
If an STX or ETX appears in the data of a message,
the receiver can simply add a DLE before the
STX or ETX to tell the receive not to treat
the following character as a marker for a packets
boundary.
Of course, if a DLE appears in the data, the
sender will have to send a pair of DLE's in its
place.
In messages that do not have any notion of a character set
like ASCII associated with them (i.e. message need not
contain multiples of 8 bits), a similar technique called
bit stuffing may be applied.
In some cases, the framing problem is solved at the physical
layer using signals that could not correspond to any sequence
of bits can be used to indicate message boundaries.
As an example, in a system that uses manchester encoding,
a signal that did not have the appropriate number of
voltage transitions could be used as a frame marker.
Beyond marking the boundaries of a frame, it is typical to
map out some skeletal structure for the frame.
For example, the layout of an ethernet frame is shown below: