Network Programming
- Communications can dedicate one data bit to indicate whether the other
data bits contain an address or data.
8
:
Reserving a set of values for use only as addresses makes it easy to distinguish
addresses from data with the limitation that messages can’t uses the reserved val-
ues for other purposes.
If the messages contain text characters (which can include characters for numer-
als), network addresses can use any values that don’t represent characters. For
example, if the messages use only US ASCII (codes 0–127), addresses can use
the values 128–255.
If the messages contain binary data, one solution is to send the data in ASCII
Hex format as described in Chapter 2. Because ASCII Hex can represent any
binary value using just 16 codes, plenty of codes remain for use as addresses.
$ 3
Many network protocols define a message format with the address and other
information in assigned locations in the message.
For example, an 8-byte message might consist of an address byte followed by
seven message bytes. On receiving a byte, a node examines the value to see if it
matches the node’s address. If it’s a match, the node reads and acts on the seven
bytes that follow, then waits for another address byte to examine. If the address
doesn’t match, the node counts but otherwise ignores the seven bytes that fol-
low.
With this method, every node has to detect every byte sent, if only to know
when the message is finished. A node that misses a byte for any reason won’t
detect the correct address bytes in future messages.
!
To make it easier to detect addresses, a protocol can define values that indicate
Start of Transmission and End of Transmission. A node that gets lost can then
recover on the next Start of Transmission code. Conventional values are 02h
(Control+B) for Start of Transmission and 03h (Control+C) for End of Trans-
mission. Some networks use other characters such as “:” or “$”. These values are
then unavailable for other uses, so using dedicated codes is useful mainly for
communications that send data as plain text.