The purpose of writing this post is reviewing my knowledge about Computer Networking subject, but i also have another plan is getting a CCNA certification in the future. So now i will move this post to CCNA category.
UDP (Universal Datagram Protocol/ User Datagram Protocol) & TCP (Transmission Control Protocol) work at transport layer. As the name of layer they work, the mission of UDP & TCP is to transfer data between computers (client, server) in 2 different ways. In other words, they are methods to establish connection over internet Protocol based network.
TCP: connection oriented, header file: 20 bytes, speed is less than UDP, used in high reliability services. TCP is heavy-weight. Require three packets to set up a socket connection (Three way handshake: SYN- Synchronize, SYN-ACK, ACK). TCP handles reliability and congestion control, have Acknowledgement segments.
UDP: connectionless oriented, header file: 8 bytes, more speed than TCP, used in real-time services, UDP is lightweight. There is no ordering message, no tracking connection, UDP does not have an option for flow control (Does not have three way handshake), No Acknowledge.
Because of pros & cons of TCP & UDP method. They will be used in different cases, if you provide services need reliability, use TCP, want to have a service requires speed in transferring data , use UDP. Besides that, TCP also have a mechanism for fixing error file data in transfer period, this leads to the speed of TCP is less than UDP. And the last is TCP have ordering in transferring data, if any data segments arriving in wrong order, TCP reorders and delivers application. Sequence number in TCP allows receivers to discard duplicate packets and properly sequence reorder packets. Acknowledgments allow senders to determine when to retransmit lost packets. (Connection oriented).
Source: Wiki, Pubnub
SYN-ACK: Synchronize Acknowledgement