Networking: TCP & UDP
TCP is a set of rules (protocols) used with IP to send data in the form of message units between computers over a network. While IP takes care of handling the actual delivery of the data, TCP takes care of keeping track of the individual units of data (packets), which a message is divided into for efficient routing through the Internet.
For instance when an HTML file is sent to a user from a Web server, the TCP program layer in the web server divides the file into one or more packets, numbers the packets, and then forwards them individually to the IP program layer.
Although each packet has the same destination IP address, it may get routed differently through the network. At the other end (the client program on the user's computer), TCP reassembles the individual packets once they have all arrived and forwards them to the users computer as a single file.
TCP is known as a connection-oriented protocol, which means that a connection is established and maintained until such time as the messages to be exchanged by the application programs at each end have been exchanged.
TCP is also responsible for ensuring that a message is divided into the packets which IP manages and for reassembling the packets back into the complete message at the other end.
TCP runs at Layer 4 of the
OSI Model.
UDP is a communications protocol which offers a limited service for computers running on an IP (Internet Protocol) network.
UDP is an alternative to TCP (Transmission Control Protocol) and when working with IP, is sometimes referred to as UDP/IP.
Like TCP, UDP uses IP to actually move data from one computer to another. Unlike TCP, however, UDP does not provide the service of dividing a message into packets (datagrams) and reassembling it at the other end. Nor does it provide sequencing of the packets which the data arrives in. This means that the application program which uses UDP, must be able to make sure that the entire message has arrived and is in the right order.
Network applications which try to save processing time due to having only small data units to exchange (and therefore very little message reassembling to do) may prefer UDP to TCP. Trivial File Transfer Protocol (TFTP) uses UDP instead of TCP.
UDP provides two services not provided by the IP layer. It provides port numbers to help distinguish different user requests and optionally, a checksum capability to verify that the data arrived intact.
UDP runs at Layer 4 of the
OSI Model.