DEV Community

Oloruntobi Ajayi
Oloruntobi Ajayi

Posted on

A Beginner's Guide to Networking Protocols: TCP, UDP, and HTTP

What is a network protocol?
A network protocol is a set of established rules that specify how to format, send and receive data so that computer network endpoints, including computers, servers, routers and virtual machines, can communicate despite differences in their underlying infrastructures, designs or standards.

To successfully send and receive information, devices on both sides of a communication exchange must accept and follow protocol conventions. In networking, support for protocols can be built into the software, hardware or both.

Without network protocols, computers and other devices would not know how to engage with each other. As a result, except for specialty networks built around a specific architecture, few networks would be able to function, and the internet as we know it wouldn't exist. Virtually all network end users rely on network protocols for connectivity.

How network protocols work: The OSI model
Network protocols break larger processes into discrete, narrowly defined functions and tasks across every level of the network. In the standard model, known as the Open Systems Interconnection (OSI) model, one or more network protocols govern activities at each layer in the telecommunication exchange. Lower layers deal with data transport, while the upper layers in the OSI model deal with software and applications.

To understand how network protocols function, it's crucial to understand the workings of the seven layers of the OSI model:

  1. Physical layer. The physical layer is the initial layer that physically connects two interoperable systems. It controls simplex or duplex modem transmissions and transfers data in bits. Additionally, it oversees the hardware that connects the network interface card (NIC) to the network, including the wiring, cable terminators, topography and voltage levels.
  2. Data-link layer. The data-link layer is responsible for the error-free delivery of data from one node to another over the physical layer. It's also the firmware layer of the NIC. It puts datagrams together into frames and gives each frame the start and stop flags. Additionally, it fixes issues brought on by broken, misplaced or duplicate frames.
  3. Network layer. The network layer is concerned with information flow regulation, switching and routing between workstations. Additionally, it divides up datagrams from the transport layer into error-free and smaller datagrams.
  4. Transport layer. The transport layer transfers services from the network layer to the application layer and breaks down data into data frames for error checking at the network segment level. This also ensures that a fast host on a network doesn't overtake a slower one. Essentially, the transport layer ensures that the entire message is delivered from beginning to end. It also confirms a successful data transmission and retransmitting of the data if an error is discovered.
  5. Session layer. The session layer establishes a connection between two workstations that need to communicate. In addition to ensuring security, this layer oversees connection establishment, session maintenance and authentication.
  6. Presentation layer. The presentation layer is also known as the translation layer because it retrieves the data from the application layer and formats it for transmission over the network. It addresses the proper representation of data, including the syntax and semantics of information. The presentation layer is also in charge of managing file-level security and transforming data to network standards.
  7. Application layer. The application layer, which is the top layer of the network, oversees relaying user application requests to lower levels. File transfer, email, remote login, data entry and other common applications take place at this layer. the OSI model Diagram showing the seven layers of the OSI model for how applications communicate over a network Every packet transmitted and received over a network contains binary data. Most computing protocols add a header at the beginning of each network packet to store information about the sender and the message's intended destination. Some protocols may also include a footer at the end with additional information. Network protocols process these headers and footers as part of the data moving among devices in order to identify messages of their own kind.

Network protocols are often outlined in an industry standard -- developed, defined and published by groups such as the following:

International Telecommunication Union, or ITU.
Institute of Electrical and Electronics Engineers, or IEEE.
Internet Engineering Task Force, or IETF.
International Organization for Standardization, or ISO.
World Wide Web Consortium, or W3C.
The TCP/IP model
A set of cooperating network protocols is called a protocol suite. The Transmission Control Protocol/Internet Protocol (TCP/IP) suite, which is typically used in client-server models, includes numerous protocols across layers, such as the data, network, transport and application layers, working together to enable internet connectivity.

These include the following:

1.TCP uses a set of rules to exchange messages with other internet points at the information packet level.

  1. User Datagram Protocol, or UDP, acts as an alternative communication protocol to TCP and is used to establish low-latency and loss-tolerating connections between applications and the internet.
  2. IP uses a set of rules to send and receive messages at the level of IP addresses.

Additional network protocols, including Hypertext Transfer Protocol (HTTP) and File Transfer Protocol (FTP), have defined sets of rules to exchange and display information. Unlike the OSI model, the TCP/IP suite consists of four layers, each with its protocols. The four layers of the TCP/IP model are the following:

  1. Application layer. This is the topmost layer of the TCP/IP model and is responsible for providing users with access to network resources. Some of the protocols included in this layer are HTTP, Simple Mail Transfer Protocol (SMTP) and FTP. 2.Transport layer. This layer ensures that segments are transmitted correctly via the communication channel. The network link between the source and destination systems is also established at this layer.
  2. Internet layer. Also known as the network layer, the internet layer receives and sends packets for the network. This layer comprises IP, Address Resolution Protocol (ARP) and Internet Control Message Protocol (ICMP).
  3. Network access layer. The network access layer of TCP/IP combines the physical and data-link layers of the OSI model. It deals with Layer 1 concerns, such as energy, bits and the media used to transport them, such as copper, fiber and wireless. Additionally, it deals with Layer 2 difficulties, including bit conversion into protocol units, such as Ethernet packets, media access control (MAC) addresses and NICs.

Types of network protocols
Generally speaking, there are three types of protocols in networking: communication, such as Ethernet; management, such as SMTP; and security, such as Secure Shell, or SSH.

Falling into these three broad categories are thousands of network protocols that uniformly handle an extensive variety of defined tasks, including authentication, automation, correction, compression, error handling, file retrieval, file transfer, link aggregation, routing, semantics, synchronization and syntax.

The following are the three types of protocols used in network communications:

  1. Network communication protocols. The efficiency of a network is determined by the communication protocols used. The formats and regulations that govern how data is exchanged between networks are formally described by these protocols. This applies to both hardware and software and is a requirement for communicating between computing systems and telecommunication systems. In addition to handling syntax, synchronization and semantic requirements that both analog and digital communications must meet to work, communication protocols also handle authentication and error detection. HTTP, UDP, TCP and Internet Relay Chat are network communication protocols.
  2. Network management protocols. To ensure steady communication and optimal performance throughout the network, network management protocols help specify the policies and processes needed to monitor, administer and maintain a computer network. They also assist in communicating these demands across the network. Simple Network Management Protocol (SNMP) and ICMP are network management protocols.
  3. Network security protocols. The primary responsibility of network security protocols is to ensure that the data in transit over the network connections are kept safe and secure. These protocols also specify how the network protects data from any unauthorized efforts to inspect or extract it. This ensures that unauthorized users, services or devices don't have access to the network. Protocols such as Secure Sockets Layer (SSL), Secure FTP and HTTP Secure (HTTPS) operate at this level.

How to employ network protocols
For network protocols to work, they must be coded within software -- either as part of the computer's operating system (OS) or as an application -- or executed within the computer's hardware. Most modern OSes possess built-in software services that are prepared to implement some network protocols. Other applications, such as web browsers, are designed with software libraries that support the protocols necessary for the application to function. In addition, TCP/IP and routing protocol support is implemented in direct hardware for enhanced performance.

Whenever a new protocol is implemented, it is added to the protocol suite. The organization of protocol suites is considered to be monolithic since all protocols are stored in the same address and built on top of one another.

What are the vulnerabilities of network protocols?
Network protocols are not designed for security. Their lack of protection can sometimes enable malicious attacks, such as eavesdropping and cache poisoning, to affect the system. The most common attack on network protocols is the advertisement of false routes, causing traffic to go through compromised hosts instead of the appropriate ones.

Cybercriminals frequently use network protocols in distributed denial-of-service assaults, which is another typical method of exploiting them. For example, in a SYN flood attack, an attacker takes advantage of the way TCP works. They send SYN packets to repeatedly initiate a TCP handshake with a server until the server is unable to provide service to legitimate users because its resources are tied up by all the fake TCP connections.

Network protocol analyzers are tools that protect systems against malicious activity by supplementing firewalls, antivirus programs and antispyware software.

Examples of network protocol uses:
Network protocols are what make the modern internet possible since they enable computers to communicate across networks without users having to see or know what background operations are occurring. Some specific examples of network protocols and their uses are the following:

  1. Post Office Protocol 3, or POP3, is the most recent version of a standard protocol that is used for receiving incoming emails.
  2. SMTP is used to send and distribute outgoing emails.
  3. FTP is used to transfer files from one machine to another. The files can be multimedia files, program files, text files and documents.
  4. Telnet is a collection of rules used to connect one system to another via a remote login. The local computer sends the request for connection, and the remote computer accepts the connection.
  5. HTTPS is a common protocol used to protect communication between two computers, one of which is using a browser and the other of which is downloading data from a web server.
  6. Gopher is a set of rules used to search for, get hold of and display documents from remote sites. Gopher operates according to the client-server model. Other network protocol examples include the following:

ARP.

  1. Blocks Extensible Exchange Protocol, or BEEP.
  2. Border Gateway Protocol, or BGP.
  3. Binary Synchronous Communications, or BSC.
  4. Canonical Text Services, or CTS.
  5. Domain Name System, or DNS.
  6. Dynamic Host Configuration Protocol, or DHCP.
  7. Enhanced Interior Gateway Routing Protocol, or EIGRP.
  8. Human Interface Device, or HID, protocol.
  9. ICMP.
  10. Internet Message Access Protocol, or IMAP.
  11. MAC.
  12. Network News Transfer Protocol, or NNTP.
  13. Open Shortest Path First, or OSPF.
  14. SSL.
  15. SNMP.
  16. Thread.
  17. Transport Layer Security, or TLS.
  18. Universal Description, Discovery and Integration, or UDDI.
  19. voice over IP, or VoIP.
  20. X10.

Network protocols are the backbone of the internet, without which it wouldn't exist. Learn about the 12 most used network protocols, as well as their purposes and use cases.

The main difference between TCP (transmission control protocol) and UDP (user datagram protocol) is that TCP is a connection-based protocol and UDP is connectionless. While TCP is more reliable, it transfers data more slowly. UDP is less reliable but works more quickly. This makes each protocol suited to different types of data transfers.

Protocols are rules that govern how data is formatted and sent over a network. TCP and UDP are two different methods for doing the same job: transferring data via the internet. They enable servers and devices to communicate so you can send emails, watch Netflix, play games, and browse web pages.

TCP creates a secure communication line to ensure the reliable transmission of all data. Once a message is sent, the receipt is verified to make sure all the data was transferred.

UDP does not establish a connection when sending data. It sends data without confirming receipt or checking for errors. That means some or all of the data may be lost during transmission.

Here are the main differences between TCP and UDP:

Factor:

Connection type
TCP:

Requires an established connection before transmitting data
UDP:
No connection is needed to start and end a data transfer
Factor:
Data sequence
TCP:
Can sequence data (send in a specific order)
UDP:
Cannot sequence or arrange data
Factor:
Data retransmission
TCP:
Can retransmit data if packets fail to arrive
UDP:
No data retransmitting. Lost data can’t be retrieved
Factor:
Delivery
TCP:
Delivery is guaranteed
UDP:
Delivery is not guaranteed
Factor:
Check for errors
TCP:
Thorough error-checking guarantees data arrives in its intended state
UDP:
Minimal error-checking covers the basics but may not prevent all errors
Factor:
Broadcasting
TCP:
Not supported
UDP:
Supported
Factor:
Speed
TCP:
Slow, but complete data delivery
UDP:
Fast, but at risk of incomplete data delivery

Which protocol is better: TCP or UDP?
It depends on what you’re doing online and the type of data being transferred. UDP is better if you’re gaming online, because its speedy data transfer allows for mostly lag-free gaming. TCP is better if you’re transferring files, like family photos, because it ensures the data arrives exactly as it was sent.

Overall, TCP and UDP are both useful protocols, so to think in terms of TCP vs UDP is a bit misleading. But depending on the type of data transfer, TCP or UDP might be better for the job. Here are some examples:

  1. TCP is best for:

icon-pros-20Email or texting

icon-pros-20File transfers

icon-pros-20Web browsing

  1. UDP is best for:

icon-pros-20Live streaming

icon-pros-20Online gaming

icon-pros-20Video chat

Here’s a detailed breakdown of the advantages and disadvantages of TCP and UDP:

Advantages of TCP
Transmission control protocol (TCP) is the protocol to choose for maximum reliability and quality. It may not be the fastest, but it gets the job done right. Here are a few advantages of the TCP protocol:

It sets up and maintains a connection between sender and receiver.

It operates independently of the operating system.

It supports many routing protocols.

It checks for errors, guaranteeing data arrives at its destination unaltered.

It confirms data arrival after delivery, or attempts to retransfer.

It’s able to send data in a particular sequence.

It optimizes the pace of data transmission based on the receiver.

Disadvantages of TCP
TCP isn’t suited for some types of data transfers, especially ones that require faster speeds. These are the drawbacks of TCP packet transmission:

It uses more bandwidth and is slower than UDP.

It’s especially slow at the beginning of a file transfer.

It can prevent data from loading if some data is lost. For example, it won’t load images on a web page until all of the page data has been delivered.

It reduces its transfer rate if the network is congested, resulting in even slower speeds.

It’s not suited for LAN and PAN networks.

It can’t multicast or broadcast.

Despite its slower speeds, TCP is the only protocol that can retransmit lost data packets. When reliability is critical, TCP is the best option.

Applications of TCP
When should you enable TCP data transfer? Most data transfers automatically use the best protocol option. But in certain circumstances — such as when using a VPN — you may need to choose a protocol to optimize your browsing experience. Enable TCP for the following activities:

Email and text messaging

Streaming pre-recorded content on sites like Netflix, Hulu, or HBO Max

Transferring files between apps and devices

General web browsing

Remote device or network administration

Advantages of UDP
UDP delivers data rapidly, and it doesn’t slow down or turn back to recollect lost data. This makes it an ideal protocol for delivering continuous data or broadcasting, such as for live streaming, video calling, and matching servers with IP addresses. Here are some of the advantages of UDP:

No connection is needed to send or receive data, so apps and operating systems work faster.

Broadcast and multicast transmission is available, meaning one UDP transmission can send data to multiple recipients.

It endures packet loss, delivering data even if it's incomplete.

Smaller packet size and less overhead reduce end-to-end delay.

Operates over a larger range of network conditions than TCP.

UDP communication is more efficient.

It can transmit live and real-time data.

Disadvantages of UDP
While UDP provides the speed you need to live a comfortable digital life, UDP isn’t as reliable as TCP. This is something to be aware of when setting up a VPN, because most VPNs run on UDP protocols to keep connection speeds high. Here are some disadvantages of using UDP:

It’s connectionless, which makes data transfer unreliable.

There’s no system in place to acknowledge a successful data transfer.

There’s no way to know if data is delivered in its original state, or at all.

It has no error control, so it drops packets when errors are detected.

In case of a data collision, routers will often drop UDP packets and favor TCP packets.

Multiple users accepting UDP data can cause congestion, and there’s no way to mitigate this.

It cannot sequence data, so data can arrive in any order or out of order.

Applications of UDP
UDP is best suited for transferring a steady flow of live data. This allows many users to access data easily and quickly, if not in perfect condition. A good example is playing an online game. UDP can keep the action moving in spite of potential errors or data loss. Here are a few applications of UDP in real life.

Online gaming

Multicasting

Video chatting/conferencing

VoIP (in-app voice calling)

Domain Name Systems (which translates domain names into IP addresses)

How does TCP work?
TCP works by using a “three-way handshake” — a three-step process that forms a connection between a device and a server. The completion of the three-step process establishes the non-stop connection, starts the transfer of data packets across the internet, delivers them intact, and acknowledges delivery.

Here’s how TCP works:

The client device initiating the data transfer sends a sequence number (SYN) to the server. It tells the server the number that the data packet transfer should begin with.

The server acknowledges the client SYN and sends its own SYN number. This step is often referred to as SYN-ACK (SYN acknowledgement).

The client then acknowledges (ACK) the server’s SYN-ACK, which forms a direct connection and begins the data transfer.

The connection between the sender and receiver is maintained until the transfer is successful. Every time a data packet is sent, it requires an acknowledgment from the receiver. So, if no acknowledgment is received, the data is resent.

If an error is acknowledged, the faulty packet is discarded and the sender delivers a new one. Heavy traffic or other issues may also prevent data from being sent. In that case, the transmission is delayed (without breaking the connection).Thanks to these controls, successful data delivery is guaranteed with TCP.

TCP works by using a three-step handshake to establish and keep a reliable connection for data transfer.TCP uses a three-step process that forms (and keeps) a connection between a device and a server.

How does UDP work?
The UDP protocol works by immediately firing data at the receiver who made a data transmission request, until the transmission is complete or terminated. Sometimes called a “fire-and-forget” protocol, UDP fires data at a recipient in no particular sequence, without confirming delivery or checking if packets arrived as intended.

While TCP establishes a formal connection via its “handshake” agreement before sending data. UDP doesn’t have time for that. It speeds up data transfer by sending packets without making any agreement with a receiver. Then, it’s up to the recipient to make sense of the data.

UDP works by firing data from server to device until all data is transferred or the connection is terminated.UDP works by rapid-firing data from sender to receiver until the transfer is completed or terminated.

Here’s an analogy to help you understand how TCP and UDP work:

Imagine you’re having lunch at the office and a friend in a different cubicle asks you for half of your sandwich. You have two options: You can walk through the maze of office desks and hand it to her, guaranteeing a secure delivery. Or, you can throw the sandwich into her cubicle from across the room, leaving the quality of the delivery up to her speed and reflexes.

The first method (TCP) is reliable, but slow. The second method (UDP) is fast, but the sandwich might not arrive in its original state — or at all.
HTTP uses TCP because the files, images, web pages which we get from the remote host should not be dropped on the way and it should be delivered in order to the HTTP client. HTTP could also use UDP but usually not, if a UDP packet containing the first part of a web page is lost, then its not retransmitted

In conclusion,
The transmission control protocol (TCP) is one of the primary ways that data is transmitted across networks on the internet. It is a connection-oriented communication protocol that allows computing devices and applications to send data and verify delivery. Along with the user datagram protocol (UDP), TCP forms the foundation of global data transferring.

The user datagram protocol (UDP) is one of the protocols that enables data transfer across networks on the internet. It is a message-oriented communication protocol that allows computing devices and applications to send data without verifying delivery. UDP is best suited for real-time communication and broadcast systems

TCP requires a reliable connection between server and recipient, which can slow down data transfer. UDP is a connectionless protocol, therefore much quicker.

TCP guarantees flawless data delivery, even if lost or damaged packets are retransmitted. UDP is a “fire-and-forget” protocol that won’t check for errors or resend lost data packets.

UDP is better for broadcasting and live streaming. TCP is better for direct communication, like email, web browsing, or transferring files.

TCP is best used for direct communication in which a reliable connection is needed, such as web browsing, email, text messaging, and file transfers. UDP is best used for live and real-time data transmission when speed is more important than reliability. UDP is normally used for online gaming, live streaming, and DNS protocols.

Yes, TCP and UDP ports are different, but they sometimes use the same port number. For example, UDP/53 and TCP/53 are both used for DNS, but they are different connection types. TCP ports comply with transmission control protocols, while UDP ports comply with user datagram protocols.

Generally, VPN protocols (such as WireGuard) are often built on UDP protocols. This prevents your device from establishing direct connections across networks, and it’s ideal for streaming, gaming, and video chatting. For a more reliable connection while emailing and messaging, switch to TCP.

TCP is the more reliable option when using a VPN, but UDP is better in certain instances. If you’re sending messages or transferring files, TCP is the best protocol to use with a VPN. TCP is also recommended for all VPN-secured web browsing. Because of its faster speeds, UDP is the better option for gaming on a VPN, live streaming, and VoIP.

Top comments (0)