Before we jump right into what TCP and UDP is all about, we have to first understand the OSI (Opens Systems Interconnection) model. Do you ever think about what happens under the hood for data to transfered from one computer to another over the internet? The OSI model is used to visualize how this data is transmitted.
The OSI model comes in to abstract the way data is transmitted between different computers with different architectures. This OSI model is made up of 7 different layers; Application layer, Presentation layer, Session layer, Transport layer, Network layer, Data link layer, Physical layer. For data to be transmitted, it will pas through all these 7 layers starting from the application layer where there is human-computer interaction to the physical layer which transmits raw bits of data to a physical medium. Our key focal point will be the Transport Layer where we will be dissecting TCP and UDP.
What is TCP?
TCP stands for Transmission Control Protocol specifies how data should be broken down and sent until it reaches its destination. It works together with the IP (internet protocol). TCP determines how to break the data into packets and the IP is responsible for addressing and routing these data packets making sure it reaches the destination chronologically.
Imagine you want to access a webpage from the browser. Once the HTTP request is made, the TCP is responsible for transmitting the html file to your browser by splitting it into various packages. These packages are numbered and sent to your browser where they will assembled back to the html file for your viewing.
It is worth noting TCP is connection-oriented where before the data is split into packets and routed, a connection between the source and destination is established. This connection is known as a handshake.
What is UDP?
The User Datagram Protocol is another protocol used to transmit data across the internet. However, it is connectionless as there is no formal connection established between the sender and receiver before the data is transmitted. UDP sends data packets directly to the computer without any connection between the two.
TCP vs UDP
Comparatively, UDP is faster in terms of transmitting data than TCP whereas TCP is more reliable in the sense that the data is certainly going to reach its destination intact. TCP is slower because it takes time establishing the connection and if there's any data loss along the line a request will be made to obtain the missing data packet. They both have their strengths and weaknesses. UDP is commonly used in time-sensitive communications where packet loss is not a big deal and it's preferable than waiting e.g live streaming. TCP is ideal for scenarios where the data must be received intact without any data loss or alteration eg emails.
NB: It is worth noting the OSI model doesn't apply to the current internet and it's the TCP/IP model which is currently used. The TCP/IP model comes from merging some of the layers of the OSI model.
Top comments (0)