TCP and UDP are protocols found in the Transport Layer. The Transport Layer is Layer 4 in the OSI Model. The Transport Layer serves the application layer by performing segmentation. Packets must be segmented because it is not possible for a packet to be sent 1 at a time.
Comparison of TCP and UDP
Transmission Control Protocol (TCP) is a connection-oriented protocol and is widely used as the basis of internet services along with the internet protocol (IP). TCP allows for reliable communication, ensuring that packets reach their destination as intended by the sender. And here are some applications that use TCP, namely:
- Web Browser
- file transfer
- etc.
User Datagram Protocol (UDP) is a minimal message-oriented or connectionless protocol. Datagram exchange in UDP does not get acknowledgment or guaranteed delivery. And when there is data lost during delivery, UDP does not perform retransmission but the retransmission is handled by another protocol. And here are some applications that use UDP, namely:
- Domain Name System (DNS)
- Video Streaming
- Voice over IP (VoIP)
- Etc.
TCP vs UDP
Actually, there are many advantages that TCP protocol has compared to UDP protocol. We know that TCP is a connection-oriented protocol, it means that every connection needs to be prepared first before data transfer begins. To do this, TCP has a 3 way handshake system. With this system, the user first initializes the connection and must get an acknowledgement from the recipient before sending data, if these requirements are met, TCP can make a connection and data delivery can be done.
3 way handshake concept
TCP is a trusted or reliable protocol. So all data sent will be guaranteed to reach the recipient. If there is a data packet that is lost or missing, the TCP protocol will send it back and if the connection is lost, the data will be requested again, so that the data packet we send will definitely reach the recipient. We cannot get all of this if we use the UDP protocol, because the UDP protocol is not reliable.
The TCP protocol allows data to be received in order according to its sending. This does not happen in the UDP protocol, because UDP is connectionless, data sent using the UDP protocol will be received out of order. The way the UDP protocol works is to send data without any guarantee whether the data will reach its destination or not. Therefore, the TCP protocol is most often used in a system.
Understanding User Datagram Protocol (UDP)
UDP is a protocol standard with STD number 6. The UDP specification can be seen in RFC 768 -- User Datagram Protocol.
UDP is basically an interface for IP applications. Where UDP does not have the function of data reliability, flow control, and error-recovery for IP communication. UDP has a process such as multiplexing/demultiplexing to send datagrams, from ports to IP datagrams. Therefore UDP is also called a connectionless-oriented protocol.
Figure 7.1 Port-based Demultiplexing Process on UDP
1. UDP Datagram Format
UDP datagram has 16 bytes as shown in Figure 7.2.
Figure 7.2 UDP Datagram Format
Where:
- Source Port: the port used to send data.
- Destination Port: the port used for data destination.
- Length: total data packet length
- Checksum: 16 bit 1's complement of the pseudo-ip-header which is an error check of the data packet.
Figure 7.3 Pseudo IP Header – UDP
2. Applications that use UDP
Applications that use the UDP protocol include:
- Trivial File Transfer Protocol (TFTP)
- Domain Name System (DNS) name servers
- Remote Procedure Call (RPC) on Network File System (NFS)
- Simple Network Management Protocol (SNMP)
- Lightweight Directory Access Protocol (LDAP).
Understanding Transmission Control Protocol (TCP)
TCP is a standard protocol with STD number 7. TCP specifications can be seen in RFC 793 -- Transmission Control Protocol.
TCP provides facilities for applications compared to UDP, because TCP provides error recovery, flow control, and reliability. TCP is also commonly referred to as a connection-oriented protocol.
2 The communication process using a TCP connection is called InterProcess Communication (IPC). IPC is illustrated as in Figure 7.4.
Figure 7.4 IPC
1. TCP Segment Format
The TCP format can be seen in Figure 7.5.
Figure 7.5 TCP Format
Where:
- Source Port : 16 bit port number. Used to receive replies.
- Destination port : 16 bit destination port number
- Sequence Number: the initial data number in the segment
- Acknowledge number: if ACK is set then this is the sequence number of data that will be received
- Data offset: the number where the data section starts.
- Reserved : for future use, set to 0
- URG : activates an emergency point on a segment
- ACK : acknowledge column
- PSH : push function
- RST : reset a connection
- SYN : to synchronize sequence numbers
- FIN : data deadline
- Window : window number for the windowing process
- Checksum: a number used to check the validity of the sender and recipient.
- Urgent Pointer: points to an urgent point in a segment.
- Options: used for other options in the datagram
- Padding: used to round data in the options section.
2. Programming Interface in TCP applications
Functions used in TCP communication include:
- Open: opens a connection by entering several parameters including: Active / Passive, Destination socket information, Local port number, Timeout value.
- Send : sends data buffer to destination
- Receive : Receive and copy data to the user's buffer.
- Close : close the connection
- Status : viewing information
- Abort: cancels all send or receive activities.
3. Applications that use TCP
Almost all network applications use TCP, application standards that use TCP include:
- Telnet
- File Transfer Protocol (FTP)
- Simple Mail Transfer Protocol (SMTP)
- Hyper-Text Transfer Protocol (HTTP).
Structure & Programming for Application Layer
The highest layer is the application layer. This layer communicates with each other between hosts and is the interface that is visible to the user on the TCP/IP protocol.
1. Characteristics of the Application
In the application layer there are several characteristics that are the same, namely:
- It is an application written by the user (user-written) or an application that is already a standard with TCP/IP products in it. TCP/IP set applications include; TELNET is used to access remote hosts through interactive terminals, FTP (File Transfer Protocol) is used to transfer files between disks o SMTP (Simple Mail Transfer Protocol) is used as a mail system on the internet.
- Using UDP or TCP transport system
- Using a client-server model.
2. Remote Procedure Call (RPC)
RPC is a protocol that allows a computer program to provide a subroutine to another computer to execute a command without the programmer having to create the program first.