User`s guide
3 Network Communication
3-16
packets while the stack at the other end is responsible for reassembling the
packets into a data stream using information in the packet headers. UDP, on
the other hand, is a packet-oriented protocol where the application itself
divides the data into packets and sends them to the other end. The other end
does not have to reassemble the data into a stream. Note, some applications
may indeed present the data as a stream when the underlying protocol is
UDP. However, this is the layering of an additional protocol on top of UDP,
and it is not something inherent in the UDP protocol itself.
•
TCP Is a Reliable Protocol, While UDP Is Unreliable — The packets that
are sent by TCP contain a unique sequence number. The starting sequence
number is communicated to the other side at the beginning of
communication. Also, the receiver acknowledges each packet, and the
acknowledgement contains the sequence number so that the sender knows
which packet was acknowledged. This implies that any packets lost on the
way can be retransmitted (the sender would know that they did not reach
their destination since it had not received an acknowledgement). Also,
packets that arrive out of sequence can be reassembled in the proper order
by the receiver.
Further, timeouts can be established, since the sender will know (from the
first few packets) how long it takes on average for a packet to be sent and its
acknowledgment received. UDP, on the other hand, simply sends the packet
and does not keep track of them. Thus, if packets arrive out of sequence, or
are lost in transmission, the receiving end (or the sending end) has no way of
knowing.
TCP communication may be compared to a telephone conversation where a
connection is required at all times and two-way streaming data (the words
spoken by each party to the conversation) are exchanged. UDP, on the other
hand, may be compared to sending letters by mail (without a return address).
If the other party is not found, or the letter is lost in transit, it is simply
discarded. The analogy fails, however, when considering the speed of
communication. Both TCP and UDP communication happen roughly at the
same speed since both use the underlying Internet Protocol (IP) layer.