Monday 9 September 2019

TCP Vs UDP | Explanation and Comparison TCP UDP port Numbers

TCP Vs UDP | Explanation and Comparison

This article is about TCP Vs UDP protocol, Explanation and its difference. Also the reason why the TCP protocol is considered more reliable than UDP protocol. We will discus both protocol in details and in the end we will compare TCP and UDP.

TCP Protocol

The function of the TCP transport protocol is similar to sending packets that are tracked from source to destination. If a shipping order is divided into several packages, the customer can check the delivery order online.
There are three basic operations that enable reliability with TCP:

  1. The numbering and tracking of data segments transmitted to a specific host from a given application
  2. The acknowledgment of data receipt
  3. The retransmission of any data without acknowledgment after a certain period


  • TCP FEATURES


    • Connection oriented : create a session between the source and destination.
    • Reliable delivery : retransmit lost or damaged data.
    • Reconstruction of ordered data : numbering and sequencing of segments to rearm data in the correct order.
    • Flow control : regulates the amount of data that is transmitted since network hosts have limited resources, such as memory or processing capacity.
    • Protocol with status : tracks the session.


  • TCP HEADER


TCP is a protocol with status information, that is, it tracks the status of the communication session. TCP adds 20 bytes of overhead to the segment header

    • Source port (16 bits) and destination port (16 bits) : used to identify the application.
    • Sequence number (32 bits) : used to rearm data.
    • Recognition number (32 bits) : indicates the data received.
    • Header length (4 bits) : known as “data offset”. Indicates the length of the TCP segment header.
    • Reserved (6 bits) : this field is reserved for the future.
    • Control bits (6 bits) : includes bit codes, or markers, that indicate the purpose and function of the TCP segment.
    • Window size (16 bits) : indicates the number of bytes that can be accepted at a time.
    • Checksum (16 bits) : used to verify errors in the header and segment data.
    • Urgent (16 bits) : indicates if the information is urgent.

  • TCP COMMUNICATION PROCESS
    • Each application process that runs on the server uses a port number.
    • An individual server cannot have two services assigned to the same port number within the same transport layer service.
    • An active server application assigned to a specific port is considered open.
    • There may be many ports open simultaneously on one server, one for each active server application.

A TCP connection is established in three steps:
    • The source client requests a client-to-server communication session with the server.
    • The server acknowledges receipt of the client-to-server communication session and requests a server-to-client communication session.
    • The source client acknowledges receipt of the server-to-client communication session.
The TCP FIN indicator (completion control marker) is set in the segment header to terminate a TCP connection.
    • When the client has no more data to send in the transmission, it sends a segment with the FIN indicator set.
    • The server sends an ACK to acknowledge the FIN to receive the client-to-server session.
    • The server sends an END to the client to end the session from server to client.
    • The client responds with an ACK to acknowledge the FIN from the server.
    • Once all segments are recognized, the session is closed.

  • TCP THREE-WAY LINK PROTOCOL

To establish the connection, the hosts make a three-way link. The three way link:
    • It states that the target device is present in the network.
    • Verify that the destination device has an active service and accept requests on the destination port number that the source client wishes to use for the session.
    • Inform the destination device that the source client tries to establish 
    • a communication session on that port number
TCP control bit fields table
CountrysideDescription
URGimportant urgent pointer field
ACKimportant field of constitution
RSTrestore connection
SYNsynchronize sequence numbers
FINISHno more issuer data
The three steps during a three-way TCP link protocol are SYN, SYN-ACK and ACK.

  • TCP RELIABILITY
    • TCP segments use sequence numbers to reassemble the segments in the original order.
    • During the configuration of the TCP session, a random initial sequence number (ISN) is chosen. Then, the ISN increases with the number of bytes transmitted.
    • The data is delivered to the application layer only when it has been received and completely reassembled.
  • TCP FLOW CONTROL

TCP also offers flow control mechanisms, the amount of data that the destination can receive and process with reliability. The flow control allows to maintain the reliability of the TCP transmission by adjusting the speed of the data flow between the source and the destination for a given session. To achieve this, the TCP header includes a 16-bit field called " window size ".

    • Window size : amount of data that an origin can transmit before receiving an acknowledgment. It determines the amount of data that the target device of a TCP session can accept and process at a time.
    • The acknowledgment of receipt . It is the next byte that the destination expects to receive.
    • Finally, network congestion usually results in packet discarding.

UDP PROTOCOL

UDP provides the basic functions to distribute data segments among the appropriate applications, with very little overhead and data checking. While TCP's reliability functions provide stronger communication between applications, they also represent an additional overhead and may cause transmission delays. There is a trade-off between the value of reliability and the burden that it implies for network resources. Adding overhead to ensure reliability for some applications could reduce the utility to the application and even be harmful.

UDP is ideal for applications that do not require reliability.

  • UDP FEATURES
    • Without connection
    • Less transmission delays.
    • There is no reconstruction of ordered data (performed by the application)
    • Unreliable Delivery
    • No flow control
    • Stateless protocol, neither the client nor the server is obliged to track the status of the communication session.
  • UDP HEADER

UDP is a protocol without status information, so if reliability is desired it must be handled by the application layer. Portions of communication in UDP are called datagrams and UDP adds only 8 bytes of overhead.

  • UDP COMMUNICATION PROCESS

UDP datagram reset
    • UDP simply reassembles the data in the order in which they were received and sends them to the application.
    • If necessary, the application must identify the correct sequence.
UDP server processes and requests
    • UDP-based server applications are assigned known or registered port numbers.
    • Requests received at a specific port are forwarded to the appropriate application based on the port numbers.
UDP client processes
    • The UDP client process dynamically selects a port number and uses it as the source port.
    • Typically, the destination port is the known or registered port number that is assigned to the server process.
    • The same pair of source or destination ports is used in the header of all datagrams used in the transaction.
    • When returning data from the server to the client, the source and destination port numbers are reversed in the datagram header.

SEVERAL CONVERSATIONS SEPARATELY

The transport layer separates and manages several communications with different transport requirements. 
  • Different applications send and receive data on the network simultaneously.
  • TCP and UDP manage these different simultaneous conversations through header fields that can uniquely identify these applications.
These unique identifiers are port numbers.
he source port number is associated with the application that originates the communication on the local host and the destination port is used to identify an application on the server (destination) -> remote host.
UDP and TCP Port Number
Port NumberProtocolApplicationAcronym
20TCPFile Transfer Protocol (data)FTP
21TCPFile Transfer Protocol (control)FTP
22TCPSafe ShellSSH
23TCPTelnet-
25TCPSimple File Transfer ProtocolSMTP
53TCP, UDPDomain Name ServiceDNS
67UDPDynamic host configuration protocol (server)DHCP
68UDPDynamic host configuration protocol (client)DHCP
69UDPTrivial File Transfer ProtocolTFTP
80TCPHypertext Transfer ProtocolHTTP
110TCPPost Office Protocol version 3 (Post Office Protocol version 3)POP3
143TCPInternet Message Access ProtocolIMAP
161UDPSimple Network Management ProtocolSNMP
443TCPSecure hypertext transfer protocolHTTPS
A server can offer more than one service simultaneously, for example, web services (80) and FTP connection (21)

PORT NUMBER GROUPS

The Internet Assigned Numbers Authority (IANA) is the regulatory body responsible for assigning different addressing standards, including port numbers. There are different types of port numbers:


  • Well-known ports : These numbers are reserved for services and applications. (For example: web browsers, email clients)
  • Registered ports : These port numbers are assigned to an entity that requests them for use with specific processes or applications. For example, Cisco port 1985 for its routing process (HSRP).
  • Dynamic or private ports : (or ephemeral) The client OS dynamically assigns them when a connection to a service is initiated.

Port Number Groups Table
Port Number RangePort Group
Between 0 and 1023Well-known ports
From 1024 to 49151Registered Ports
From 49152 to 65535Dynamic or private ports

THE NETSTAT COMMAND

It is used to inspect TCP connections that are open (active) and running on the network host. The netstat command will attempt to resolve IP addresses in domain names and port numbers in known applications. The -n option can be used to display IP addresses and port numbers in their numerical format.

TCP OR UDP

Which transport layer protocol is correct for the appropriate application? For some applications, the segments must arrive in a very specific sequence so that they can be processed correctly. With other applications, the data is considered useful once all are received in full. In both cases, TCP is used as the transport protocol

  • TCP is better for databases, web browsers, email clients, etc. (Telnet, FTP, SMTP, HTTP)

In other cases, an application can tolerate some data loss during transmission over the network, but transmission delays are not allowed. UDP is the best option for these applications, since less network overhead is required.


  • UDP is better for live streaming audio or video, VoIP, etc. (TFTP, IPTV, DHCP, DNS SNMP, VoIP)


No comments:

Post a Comment