blog posts

What is the difference between TCP and UDP protocols?

You may have experienced TCP and UDP while fixing up port forwarding on the router or while configuring firewall software; But do you know what these two protocols are and what the discrepancies are?

TCP and UDP are two protocols used for various types of data. Instruments and computers connected to the Internet use a protocol called TCP / IP to transmit with each other. TCP / IP is a set of protocols used by devices to communicate over the Internet and most local area networks. The name TCP / IP is derived from two main protocols: Transmission Control Protocol (TCP) and Internet Protocol (IP). TCP equips applications with a way to deliver and receive packets sorted and reviewed over the network. The User Datagram Protocol (UDP) is used by applications to provide faster data flow by stopping error checking.

When configuring home network hardware or software, you may require to know the difference between the TCP and UDP protocols.

Attributes of TCP and UDP protocols

When a computer in London wants to send data to a computer in New York, it must understand the IP address of the destination computer (the computer in New York). This information is often sent via UDP and TCP. TCP and UDP are protocols used to send bits of data or packets over the Internet. Both protocols depend on the IP protocol; In other words, it does not matter if you send a packet via TCP or UDP, in which case the packet will be sent to an IP address.

TCP protocol

Utilizing Transfer Control Protocol (TCP), the data transmitter computer connects straight to the computer to which the data is being sent and stays connected for as long as the transfer takes place. With the help of this method, these two computers can disconnect after ensuring data entry is safe and correct. This method of data transfer is faster and safer, But it puts more load on the computer because it has to control the connection and the data in it. For instance, imagine you pick up the phone and call your friend; When both are done, you both hang up and release the connection.

Sent packets are tracked by TCP so no data is lost or corrupted during transmission; This is why downloading files will not be interrupted even if the network is down. Of course, if the receiver is completely offline, your computer will stop sending the packet and you will see an error message saying that it can not communicate with the host. TCP performs this in two ways:

  • Demand packages by numbering them
  • Inspect the error by sending a reply from the recipient to the sender stating that he has received the message.

If the sender does not receive the correct response, it can resend the packets to make sure the recipient has received them accurately. Process Explorer and other system processing tools can suggest the type of communication created by a process. In the image below, you can see the Chrome browser with open TCP connections to diverse web servers.

مرورگر کروم با ارتباطات باز TCP به انواع سرورهای وب

UDP protocols

Utilizing the User Datagram Protocol (UDP), the computer that sends the information caches the data in small packets and frees them up over the network, hoping to reach their destination. This means that UDP, like TCP, does not connect directly to the receiving computer; Rather, it sends the data abroad and depends on devices between the sender and receiver computers to receive the data at the intended destination.

This method of transmission does not assure that the transmitted data will contact the destination. On the other hand, this method of transmission has very little overhead; Hence, its use is for services that do not care about the successful receipt and transmission of data on the first try. A simple example of this is the use of older postal services; You put your letter in the mailbox and hope the postal service will get it to the right place. This is done most of the time; But sometimes it gets lost along the way.

Data transfer using UDP is faster; Because the sender does not wait to make sure the recipient has obtained the package; But continues to send the following packages. If the receiver loses several UDP packets, they are lost and the sender does not resend them. UDP is used when speed is the main standard and error correction is not required. UDP is often used in live video broadcasts and online games.

استفاده از UDP در بازی‌های آنلاین

TCP or UDP port Which of them?

Every computer or device on the Internet is identified by a special number called an IP address. This address is used to identify your computer among the millions of other computers connected to the Internet. When information is sent over the Internet, your computer receives this information using TCP or UDP ports.

You have an IP address and a considerable number of ports in this IP address and you can have a total of 65535 TCP ports and 65535 UDP ports. When an application on your computer receives or sends information over the Internet, it basically sends the data to an IP address and an exact port on the destination computer and receives the data on a random port on your computer. The TCP protocol uses the TCP port to send and receive data, and the UDP protocol utilizes the UDP port to send and receive data.

How web server accepts a remote computer connection?

In order for a web server to accept a remote computer connection demand, it must connect the web server application to a local port. The web server then uses this port to listen and accept remote computer communication. Web servers generally connect to port 80 TCP; The same port that the HTTP protocol uses by default and then waits for remote computers to connect. Once a device is connected, it sends the requested web pages to the device remotely and disconnects when done.

On the other hand, if you are a remote user who wants to connect to a web server, the opposite is true; Your web browser selects a random TCP port from a specific range of port numbers and tries to connect to port 80 at the web server’s IP address. When the connection is designated. The web browser sends the request to a specific web page and receives it from the webserver; After this, both computers will disconnect.

But how do you set up an FTP server (which permits you to transfer and download files from remote computers to the same webserver)? FTP servers use TCP 20 and TCP 21 ports to send and receive information. So you will not have any altercations with the web server running on TCP 80 port. As a result, when the FTP server program runs. It connects to TCP 20 and TCP 21 ports and pauses for the connection to send and receive data.

Conclusion

Applications use TCP or UDP relying on their requirements and the decision of their creators. Most programs require TCP error correction and tranquility, But some programs need to speed up and reduce UDP overhead. Unless you are a network administrator or software developer, this should not influence your business much.

If you have configured your router or firewall software and you are not sure if a program is using TCP or UDP. You can just select Both to have your router or firewall apply the same rule to TCP and UDP traffic.

Source:https://www.zoomit.ir/computer-learning/370788-difference-between-tcp-udp/