UDP and TCP: Essential Protocols in Networking

In the vast landscape of networking, the protocols UDP (User Datagram Protocol) and TCP (Transmission Control Protocol) play pivotal roles in facilitating seamless data transmission. This article delves into the fundamentals of UDP and TCP, exploring topics such as UDP and TCP overviews, Port Numbers, TCP communication process, Reliability and Flow Control in TCP, as well as UDP communication and the transportation of data.

UDP Overview

UDP is a connectionless protocol known for its simplicity and efficiency in transmitting data packets. It operates without establishing a direct connection between sender and receiver, making it ideal for applications that prioritize speed over reliability.

UDP features include the following:

  • Data is reconstructed in the order that it is received.
  • Any segments that are lost are not resent.
  • There is no session establishment.
  • The sending is not informed about resource availability.

UDP is a stateless protocol, meaning neither the client, nor the server, tracks the state of the communication session. If reliability is required when using UDP as the transport protocol, it must be handled by the application.

One of the most important requirements for delivering live video and voice over the network is that the data continues to flow quickly. Live video and voice applications can tolerate some data loss with minimal or no noticeable effect, and are perfectly suited to UDP.

The blocks of communication in UDP are called datagrams, or segments. These datagrams are sent as best effort by the transport layer protocol.

TCP Overview

TCP, in contrast, is a connection-oriented protocol that ensures reliable and ordered delivery of data packets. It establishes a connection, verifies data integrity, and manages flow control to guarantee complete data transmission.

To understand the differences between TCP and UDP, it is important to understand how each protocol implements specific reliability features and how each protocol tracks conversations.

In addition to supporting the basic functions of data segmentation and reassembly, TCP also provides the following services:

  • Establishes a Session – TCP is a connection-oriented protocol that negotiates and establishes a permanent connection (or session) between source and destination devices prior to forwarding any traffic. Through session establishment, the devices negotiate the amount of traffic that can be forwarded at a given time, and the communication data between the two can be closely managed.
  • Ensures Reliable Delivery – For many reasons, it is possible for a segment to become corrupted or lost completely, as it is transmitted over the network. TCP ensures that each segment that is sent by the source arrives at the destination.
  • Provides Same-Order Delivery – Because networks may provide multiple routes that can have different transmission rates, data can arrive in the wrong order. By numbering and sequencing the segments, TCP ensures segments are reassembled into the proper order.
  • Supports Flow Control – Network hosts have limited resources (i.e., memory and processing power). When TCP is aware that these resources are overtaxed, it can request that the sending application reduce the rate of data flow. This is done by TCP regulating the amount of data the source transmits. Flow control can prevent the need for retransmission of the data when the resources of the receiving host are overwhelmed.

TCP is a stateful protocol which means it keeps track of the state of the communication session. To track the state of a session, TCP records which information it has sent and which information has been acknowledged. The stateful session begins with the session establishment and ends with the session termination.

TCP is a good example of how the different layers of the TCP/IP protocol suite have specific roles. TCP handles all tasks associated with dividing the data stream into segments, providing reliability, controlling data flow, and reordering segments. TCP frees the application from having to manage any of these tasks. Applications, like those shown in the figure, can simply send the data stream to the transport layer and use the services of TCP.

Port Numbers

Port numbers act as endpoints in a network for specific protocols. They allow different applications on the same device to communicate concurrently. For example, commonly used port numbers are 80 for HTTP, 443 for HTTPS, and 22 for SSH.

# Python example demonstrating port numbers
import socket

# Get port number for HTTP
http_port = socket.getservbyname('http')
print("HTTP Port Number:", http_port)

As you have learned, there are some situations in which TCP is the right protocol for the job, and other situations in which UDP should be used. No matter what type of data is being transported, both TCP and UDP use port numbers.

The TCP and UDP transport layer protocols use port numbers to manage multiple, simultaneous conversations. As shown in the figure, the TCP and UDP header fields identify a source and destination application port number.

The source port number is associated with the originating application on the local host whereas the destination port number is associated with the destination application on the remote host.

For instance, assume a host is initiating a web page request from a web server. When the host initiates the web page request, the source port number is dynamically generated by the host to uniquely identify the conversation. Each request generated by a host will use a different dynamically created source port number. This process allows multiple conversations to occur simultaneously.

In the request, the destination port number is what identifies the type of service being requested of the destination web server.. For example, when a client specifies port 80 in the destination port, the server that receives the message knows that web services are being requested.

A server can offer more than one service simultaneously such as web services on port 80 while it offers File Transfer Protocol (FTP) connection establishment on port 21.

Netstat command

Unexplained TCP connections can pose a major security threat. They can indicate that something or someone is connected to the local host. Sometimes it is necessary to know which active TCP connections are open and running on a networked host. Netstat is an important network utility that can be used to verify those connections. As shown below, enter the command netstat to list the protocols in use, the local address and port numbers, the foreign address and port numbers, and the connection state.

C:\> netstat

Active Connections

  Proto  Local Address          Foreign Address            State
  TCP    192.168.1.124:3126     192.168.0.2:netbios-ssn    ESTABLISHED
  TCP    192.168.1.124:3158     207.138.126.152:http       ESTABLISHED
  TCP    192.168.1.124:3159     207.138.126.169:http       ESTABLISHED
  TCP    192.168.1.124:3160     207.138.126.169:http       ESTABLISHED
  TCP    192.168.1.124:3161     sc.msn.com:http            ESTABLISHED
  TCP    192.168.1.124:3166     www.cisco.com:http         ESTABLISHED
(output omitted)
C:\>

By default, the netstat command will attempt to resolve IP addresses to domain names and port numbers to well-known applications. The -n option can be used to display IP addresses and port numbers in their numerical form.

In conclusion, understanding the nuances between UDP and TCP is crucial for network administrators and developers. While TCP ensures reliable data delivery with intricate communication protocols, UDP provides faster but less guaranteed transmission, making it ideal for specific applications.

By comprehending the workings of UDP and TCP, one can optimize network performance, tailor protocols to suit application needs, and ensure efficient data transmission across various network environments.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top