The next step is to look at the tasks that an application protocol must perform and how it goes about performing them. Although an exhaustive exposition might identify a dozen (or so) areas, the ones we’re interested in are:
Tells how the beginning and ending of each message is delimited.
Tells how a message is represented when exchanged.
Tells how errors are described.
Tells how independent exchanges are handled.
Tells how the peers at each end of the connection are identified and verified.
Tells how the exchanges are protected against third-party interception or modification.
A notable absence in this list is naming—we’ll explain why later on.
There are three commonly used approaches to delimiting messages: octet-stuffing, octet-counting, and connection-blasting.
An example of a protocol that uses octet-stuffing is SMTP. Commands in SMTP are line-oriented (each command ends in a CR-LF pair). When an SMTP peer sends a message, it first transmits the
DATA command, then it transmits the message, then it transmits a
. (dot) followed by a CR-LF. If the message contains any lines that begin with a dot, the sending SMTP peer sends two dots; similarly, when the other SMTP peer receives a line that begins with a dot, it discards the dot, and, if the line is empty, it knows it’s received the entire message. Octet-stuffing has the property that you don’t need the entire message in front of you before you start sending ...