At any time, a host may be using several network connections to various services on other hosts. IP allows packets to be routed between hosts on an Internet, but once a packet reaches its destination host, a mechanism is needed whereby it can be routed to the appropriate application. IP addresses themselves do not provide sufficient information to do this.
A solution to the problem is to use a higher-level protocol for this task,
while still using IP as the underlying delivery mechanism. The
simplest such higher-level protocol is the
User Datagram Protocol ,
or UDP. UDP datagrams consists of a header and zero or more bytes
of actual data. The header has four fields: the source and destination
ports, a data integrity
checksum whose use is optional, and the length of the
datagram. The `ports'
are 16-bit numbers used to identify the connection
end points on either side. A particular network connection is then
identified by a four-tuple (source address, source port, destination
address, destination port). In principle this scheme allows for up
to
unique UDP connections between any two
hosts.
UDP is still connectionless and unreliable. To support connection-oriented applications which require reliable, in-sequence data streams, the Transport Control Protocol or TCP is used. Like UDP, TCP also uses ports to identify connection endpoints. Checksum usage in TCP is mandatory to ensure reliability. TCP headers include sequence numbers representing a byte offset in the data stream; these sequence numbers are used on the receiving end to arrange data received in TCP packets in the correct order. TCP makes use of acknowledgments to inform the sender that data has arrived correctly at the recipient (an acknowledgment consists of the sequence number of the next expected packet).