While sending the data ,To separate two frames we use flags,a flag may be any sequence of characters which indicates start and end of the frame.The problem may occur if the flag byte occurs in the data of the frame,to resolve the problem we stuff "ESC" string before each flag byte in the data.
If the "ESC" occurs in middle of the data then another "ESC" byte is inserted before "ESC" byte in the data.
At reciver side if the two esc sequences are seen then it removes one esc,if esc is followed with some data then it removes esc sequence and considers the remaining data.
If the "ESC" occurs in middle of the data then another "ESC" byte is inserted before "ESC" byte in the data.
At reciver side if the two esc sequences are seen then it removes one esc,if esc is followed with some data then it removes esc sequence and considers the remaining data.