Internet Services  «Prev  Next»

Lesson 4 TCP/IP and UDP/IP
Objective Relate TCP and UDP protocols to IP.

Relate TCP and UDP Protocols to IP and Linux Internet Services

Internet Protocol is a simple protocol, and by itself, is insufficient for most users' demands. To meet these demands, two other protocols work in conjunction IP:
  1. (TCP) Transmission Control Protocol: a set of rules that governs the delivery of data over the Internet or other network that uses the Internet Protocol, and sets up a connection between the sending and receiving computers.
  2. (UDP) User Datagram Protocol:[1] UDP (User Datagram Protocol) is an alternative communications protocol to Transmission Control Protocol (TCP) used primarily for establishing low-latency and loss tolerating connections between applications on the Internet.

TCP, UDP, and HTTP

  • TCP Protocol: Any applications that require reliable data transfer use TCP. TCP keeps track of individual IP packets as they arrive. Once all packets arrive, TCP assembles them into a single unit. TCP makes sure the packets are arranged in the sent order before giving the data to the operating system. If packet delivery or corruption errors occur with TCP transitions, the sending host will either receive a negative acknowledgement (a NACK) or it will not receive an acknowledgment (an ACK). Either way, the source host will re-transmit the TCP packet to the destination host.
    TCP is a connection-oriented protocol. This means that TCP constantly checks the status of both the sender's and the receiver's connections, which flows alongside the transmitted data, for any inconsistencies. Irregularities signal a problem with the connection; when TCP detects any connection inconsistencies, it takes steps to correct the problem.
  • UDP Protocol: UDP is often used by applications that require rapid transmittal of data and don't mind if a few packets are lost. For example, the Domain Name System (DNS), trivial file transfer protocol (TFTP), and Internet multi-media applications typically use UDP. UDP provides a wrapper around IP that allows the operating system to verify the packet arrived intact by computing a checksum[2] and comparing it to the sent checksum. Unlike TCP, UDP is a connection-less protocol. It does not use status information to take corrective action. Because of this lack of connection, UDP is often referred to as an "unreliable" protocol.
  • HTTP Protocols: The HTTP (Hypertext Transfer Protocol) is an essential protocol used for transmitting data over the internet. Here are its essential characteristics:
    1. Stateless: Each HTTP request from a client to server is independent. The server does not store any state about the client. This means each request must contain all the information necessary to understand and process it.
    2. Connectionless: After making a request, the client disconnects from the server and waits for a response. The server processes the request and re-establishes the connection to send the response.
    3. Resource Identification: HTTP uses Uniform Resource Identifiers (URIs) to identify resources. These resources can be documents, images, files, and other types of content.
    4. Request-Response Model: The protocol works on a request-response model where the client sends an HTTP request to the server, and the server sends back an HTTP response.
    5. Methods: HTTP defines several methods indicating the desired action to be performed on the resource. Common methods include:
      • `GET`: Retrieve data from the server.
      • `POST`: Send data to the server.
      • `PUT`: Update a resource on the server.
      • `DELETE`: Remove a resource from the server.
      • `HEAD`: Similar to `GET` but only retrieves the headers and not the body.
      • `OPTIONS`: Describes the communication options for the target resource.
    6. Headers: HTTP requests and responses include headers that provide metadata about the request or response. These headers can include information about content type, length, encoding, and more.
    7. Status Codes: HTTP responses include status codes that indicate the outcome of the request. These codes are grouped into categories:
      • `1xx`: Informational responses.
      • `2xx`: Successful responses (e.g., `200 OK`).
      • `3xx`: Redirection messages (e.g., `301 Moved Permanently`).
      • `4xx`: Client errors (e.g., `404 Not Found`).
      • `5xx`: Server errors (e.g., `500 Internal Server Error`).
    8. Content Negotiation: HTTP supports content negotiation, allowing clients and servers to agree on the best format for the response (e.g., JSON, XML, HTML).
    9. Security: HTTP can be secured with HTTPS (HTTP Secure), which uses SSL/TLS to encrypt the data transmitted between the client and server, ensuring privacy and data integrity.
    10. Extensibility: HTTP is designed to be extensible, allowing for custom methods, headers, and status codes to be defined as needed.
    These characteristics make HTTP a flexible, reliable, and widely-used protocol for web communication.
You might be asking yourself, how does TCP ensure that packets are received in the correct order and without errors?


Three Mechanisms 1. Sequence numbers 2. (ACKs) Acknowledgments 3. Checksums

  1. Sequence Numbers:
    • Purpose: Sequence numbers are the backbone of TCP's ordering and reliability. Each byte of data transmitted is assigned a unique sequence number. This allows the receiver to determine the correct order in which to reassemble the data, even if packets arrive out of order or are lost.
    • How it Works:
      • The initial sequence number (ISN) is a randomly generated number chosen at the beginning of a TCP connection.
      • Every subsequent byte is assigned a sequence number that is the ISN plus the byte's position in the data stream.
      • Each TCP packet includes the sequence number of the first byte of data it carries.
    • Example: Let's say the ISN is 1000. If the sender wants to transmit a message of 100 bytes, the first byte will have sequence number 1000, the second will have 1001, and so on until the last byte, which will have sequence number 1099.
  2. Acknowledgments (ACKs):
    • Purpose: ACKs provide a way for the receiver to confirm the successful receipt of data. They also help regulate the flow of data between the sender and receiver.
    • How it Works:
      • The receiver sends an ACK packet back to the sender after receiving a data packet.
      • The ACK packet contains an acknowledgment number, which is the sequence number of the next byte of data the receiver expects.
      • This tells the sender that all bytes up to that point have been received correctly.
    • Example: If the receiver sends an ACK with acknowledgment number 1050, it means it has received all bytes up to sequence number 1049 and is now expecting the byte with sequence number 1050.
  3. Checksums
    • Purpose: Checksums are used to detect errors that might occur during transmission, such as bit flips caused by electrical interference.
    • How it Works:
      • The sender calculates a checksum based on the data in the packet, using a mathematical algorithm.
      • This checksum is included in the packet header.
      • The receiver recalculates the checksum using the same algorithm.
      • If the calculated checksum matches the received checksum, it means the data was transmitted without errors. If not, it indicates corruption, and the packet is discarded.
    • Types: TCP typically uses a 16-bit checksum. There are other types of checksums with varying levels of error detection capability.

Putting it Together
These three mechanisms work in tandem to ensure reliable data transmission:
  1. Sequence numbers ensure that data is reassembled in the correct order.
  2. ACKs confirm that data has been received correctly and allow for flow control.
  3. Checksums detect errors in transmitted data.

This combination of techniques makes TCP a robust and reliable protocol, capable of handling the challenges of data transmission over unreliable networks.
The next lesson defines port numbers.
[1]User Datagram Protocol (UDP): Transfers data without first making a persistent connection between two systems the way TCP does. Sometimes called unreliable transport.
[2]Checksum: A value computed from a quantity of data and transmitted alongside the data. The receiver can verify the data's integrity by computing the checksum again and comparing the newly computed value to the transmitted one.

SEMrush Software 4 SEMrush Banner 4