contact@embeddedgeeks.com
Embedded World

TCP / IP & UDP Protocols

The TCP/IP suite is a set of protocols used on computer networks today (most notably on the Internet). It provides end-to-end connectivity by specifying how data should be packetized, addressed, transmitted, routed, and received on a TCP/IP network. This functionality is organized into four abstraction layers and each protocol in the suite resides in a particular layer.

The TCP/IP suite is named after its most important protocols, the Transmission Control Protocol (TCP) and the Internet Protocol (IP). Some of the protocols included in the TCP/IP suite are:

  • ARP (Address Resolution Protocol) – used to associate an IP address with a MAC address.
  • IP (Internet Protocol) – used to deliver packets from the source host to the destination host based on the IP addresses.
  • ICMP (Internet Control Message Protocol) – used to detects and report network error conditions. Used in ping.
  • TCP (Transmission Control Protocol) – a connection-oriented protocol that enables reliable data transfer between two computers.
  • UDP (User Datagram Protocol) – a connectionless protocol for data transfer. Since a session is not created before the data transfer, there is no guarantee of data delivery.
  • FTP (File Transfer Protocol) – used for file transfers from one host to another.
  • Telnet (Telecommunications Network) – used to connect and issue commands on a remote computer.
  • DNS (Domain Name System) – used for hostnames to the IP address resolution.
  • HTTP (Hypertext Transfer Protocol) – used to transfer files (text, graphic images, sound, video, and other multimedia files) on the World Wide Web.

The following table shows which protocols reside on which layer of the TCP/IP model:

tcp ip protocols layers

TCP Explained

One of the main protocols in the TCP/IP suite is the Transmission Control Protocol (TCP). TCP provides reliable and ordered delivery of data between applications running on hosts on a TCP/IP network. Because of its reliable nature, TCP is used by applications that require high reliability, such as FTP, SSH, SMTP, HTTP, etc.

TCP is connection-oriented, which means that, before data is sent, a connection between two hosts must be established. The process used to establish a TCP connection is known as the three-way handshake. After the connection has been established, the data transfer phase begins. After the data is transmitted, the connection is terminated.

One other notable characteristic of TCP is its reliable delivery. TCP uses sequence numbers to identify the order of the bytes sent from each computer so that the data can be reconstructed in order. If any data is lost during the transmission, the sender can retransmit the data.

Because of all of its characteristics, TCP is considered to be complicated and costly in terms of network usage. The TCP header is up to 24 bytes long and consists of the following fields:

tcp header
  • source port – the port number of the application on the host sending the data.
  • destination port – the port number of the application on the host receiving the data.
  • sequence number – used to identify each byte of data.
  • acknowledgment number – the next sequence number that the receiver is expecting.
  • header length – the size of the TCP header.
  • reserved – always set to 0.
  • flags – used to set up and terminate a session.
  • window – the window size the sender is willing to accept.
  • checksum – used for error-checking of the header and data.
  • urgent – indicates the offset from the current sequence number, where the segment of non-urgent data begins.
  • options – various TCP options, such as Maximum Segment Size (MSS) or Window Scaling.

UDP Explained

One other important protocol in the TCP/IP site is User Datagram Protocol (UDP). This protocol is basically a scaled-down version of TCP. Just like TCP, this protocol provides delivery of data between applications running on hosts on a TCP/IP network, but, unlike TCP, it does not sequence the data and does not care about the order in which the segments arrive at the destination. Because of this, it is considered to be an unreliable protocol. UDP is also considered to be a connectionless protocol since no virtual circuit is established between two endpoints before the data transfer takes place.

Because it does not provide many features that TCP does, UDP uses much less network resources than TCP. UDP is commonly used with two types of applications:

  • applications that are tolerant of the lost data – VoIP (Voice over IP) uses UDP because if a voice packet is lost, by the time the packet would be retransmitted, too much delay would have occurred, and the voice would be unintelligible.
  • applications that have some application mechanism to recover lost data – Network File System (NFS) performs recovery with application layer code, so UDP is used as a transport-layer protocol.

The UDP header is 8 bytes long and consists of the following fields:

udp header

Here is a description of each field:

  • source port – the port number of the application on the host sending the data.
  • destination port – the port number of the application on the host receiving the data.
  • length – the length of the UDP header and data.
  • checksum – checksum of both the UDP header and UDP data fields.

NOTE
UDP is a Transport layer protocol (Layer 4 of the OSI model).