Designing an application protocol
The parts of a protocol: roles, messages and reply codes, text or binary format, message framing, the session state machine, errors, timeouts and version, with HTTP/1.1 and SMTP as examples.
- 32 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- On the diagram
- Scenarios
A few cards from the deck
Application protocol: what is it?
Show the answer
A set of rules fixing the messages two programs exchange, their format and their allowed order, on top of a transport such as TCP.
TCP delivers bytes, not meaning. The protocol says who speaks first, what each message means and what happens when something goes wrong. HTTP and SMTP are examples.
Specification: type on 1 byte, text length on 2 big-endian bytes, then the text in ASCII. Which bytes (in hexadecimal) make the type 2 message carrying “OUI”?
02 00 03 4F 55 4902 03 00 4F 55 4902 00 06 4F 55 4902 00 03 6F 75 69
Show the answer
02 00 03 4F 55 49Type 02, length 3 on two big-endian bytes (00 03), then “O” = 4F, “U” = 55 and “I” = 49. The second choice writes the length little-endian, the third counts the whole message (1 + 2 + 3 = 6 bytes) instead of the text alone, and the last encodes “oui” in lower case.
Over TCP, a single recv may return … of a message or … glued together: the protocol must frame them.
Show the answer
Over TCP, a single recv may return half of a message or two messages glued together: the protocol must frame them.
The receiver must therefore accumulate bytes in a buffer and only handle a message once it is complete.
Message framing: what is it?
Show the answer
A method that lets the receiver know where a message ends in a byte stream: separator, length prefix or fixed size.
TCP keeps no boundary: a
recvreturns half a message or two glued messages. SMTP separates with\r\n, HTTP/1.1 gives the body size withContent-Length.