Implementing Byte Stuffing using Java

19 Nov, 2021
At Sender Side
Enter the Message to be Sent : 
DDEDFFDE
The data being sent (with byte stuffed) is : FDDEEDEFEFDEEF
Sending Message....
Thanks for the Feedback Server!!

At Receiver Side
Message Received...Successfully!!!
The Stuffed Message is : FDDEEDEFEFDEEF
The Destuffed Message is : DDEDFFDE
Messaging is over.....EXITING
From the above example we can see how the original data is recovered at the receiver end. ApproachAt Sender (Client) Side  
Data of each frame at the sender side, is first stuffed with 8-bit flag sequence (‘F’) at the beginning and end of each frame.Next, the data is scanned to see if any similar flag sequence (‘F’) forms a part of it or not. If yes, then before each such flag sequence, an extra escape sequence (‘E’) is stuffed.Now, if any similar escape sequence (‘E’) is found to form a part of the data to be sent, then an extra escape sequence (‘E’) is stuffed before the occurrence of each such escape sequence.Finally, this stuffed data is sent by the sender.The receiver skips over the first and last bytes of data received, as they are merely for signalling the beginning and end of one frame, respectively and does not carry any useful data.From the next byte on wards data is scanned and if two escape sequences (‘E’) are found in succession, the first one is de-stuffed. Similarly, if an escape sequence is followed by a flag sequence (‘F’), the former is de-stuffed.This strategy helps the receiver recover the actual sent data, accurately.
Data of each frame at the sender side, is first stuffed with 8-bit flag sequence (‘F’) at the beginning and end of each frame.
Next, the data is scanned to see if any similar flag sequence (‘F’) forms a part of it or not. If yes, then before each such flag sequence, an extra escape sequence (‘E’) is stuffed.
Now, if any similar escape sequence (‘E’) is found to form a part of the data to be sent, then an extra escape sequence (‘E’) is stuffed before the occurrence of each such escape sequence.
Finally, this stuffed data is sent by the sender.The receiver skips over the first and last bytes of data received, as they are merely for signalling the beginning and end of one frame, respectively and does not carry any useful data.From the next byte on wards data is scanned and if two escape sequences (‘E’) are found in succession, the first one is de-stuffed. Similarly, if an escape sequence is followed by a flag sequence (‘F’), the former is de-stuffed.This strategy helps the receiver recover the actual sent data, accurately.
The receiver skips over the first and last bytes of data received, as they are merely for signalling the beginning and end of one frame, respectively and does not carry any useful data.From the next byte on wards data is scanned and if two escape sequences (‘E’) are found in succession, the first one is de-stuffed. Similarly, if an escape sequence is followed by a flag sequence (‘F’), the former is de-stuffed.This strategy helps the receiver recover the actual sent data, accurately.
The receiver skips over the first and last bytes of data received, as they are merely for signalling the beginning and end of one frame, respectively and does not carry any useful data.
From the next byte on wards data is scanned and if two escape sequences (‘E’) are found in succession, the first one is de-stuffed. Similarly, if an escape sequence is followed by a flag sequence (‘F’), the former is de-stuffed.
This strategy helps the receiver recover the actual sent data, accurately.
kapoorsagar226
Computer Networks
Java Programs
Computer Networks
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.