Study notes about TCP, IP, HTTP, HTTPS (detailed version)

1. HTTP (Hypertext Transfer Protocol)

HTTP (Hypertext Transfer Protocol) is an application layer protocol used to transfer data between web browsers and web servers. It is based on the client-server model, where the client initiates a request and receives the server's response. It is divided into text as follows: hypertext (Hypertext), transmission (Transfer), protocol (Protocol), the relationship is as follows:

Hypertext mainly includes texts, pictures, videos and other texts that are expanded on the semantics of traditional texts.

The transmission is in charge of the transmission carrier, and the binary data packet is transmitted between two terminals. The party that transmits the data is called the requester, and the party that receives the data is called the responder. 

HTTP works as follows:

  1. Client sends request: The client (usually a web browser) sends an HTTP request to the server. A request includes a request line, request headers, and a request body. The request line contains the request method (GET, POST, etc.) and the requested URL address. Request headers contain various information such as user agent, content type, etc. The request body is optional and used to transmit data.

  2. Server processing request: After receiving the request, the server performs corresponding operations according to the requested URL and other related information. Actions may include reading files, querying databases, generating dynamic content, and more.

  3. Server sends response: The server generates an HTTP response, including the response line, response headers, and response body. The response line contains the status code of the response (e.g. 200 for success, 404 for not found, etc.). Response headers contain various information such as content type, cache settings, etc. The response body contains the actual data to be transmitted to the client.

  4. The client receives the response: After receiving the server's response, the client performs corresponding processing according to the content of the response. If the response contains HTML code, the browser renders the page for display.

Features of the HTTP protocol include:

  • Simple: HTTP communicates using a straightforward text format that is easy to understand and debug.
  • Connectionless: Each request is independent and the server does not keep any state information about the client.
  • Stateless: The server will not record previous requests and responses, each request is independent, and functions that need to maintain sessions or states are implemented through other mechanisms (such as cookies).
  • Extensible: The HTTP protocol can be extended by adding new request methods, header fields, etc.

In addition to the common GET and POST request methods, HTTP also supports other methods (such as PUT, DELETE, etc.) and many header fields (such as Content-Type, Authorization, etc.) to meet different types of requests and data transmission needs.

2. Introduction to TCP (Transmission Control Protocol) protocol

TCP is a connection-oriented reliable transport protocol, which plays an important role in network communication. The following is a detailed introduction to TCP:

  1. Connection-oriented: TCP transmits data by establishing a virtual connection. After the connection is established between the communicating parties, reliable data transmission can take place.

  2. Reliability: TCP provides reliable data transmission services. It uses techniques such as confirmation mechanisms, serial numbers, and checksums to ensure the integrity and accuracy of data. In the event of data loss or errors, TCP automatically retransmits the lost data and reassembles the data in the correct order.

  3. Flow control: TCP uses a sliding window mechanism for flow control. The receiver can inform the sender of its own buffer size, thereby limiting the amount of data sent by the sender and avoiding overload.

  4. Congestion control: TCP performs congestion control through the congestion window mechanism. It adjusts the sending rate according to the congestion level of the network to avoid network congestion and maintain network stability.

  5. Byte stream-oriented: TCP divides data into smaller segments and transmits them in the form of byte streams. This means that applications don't need to worry about fragmentation and reassembly of data, because TCP handles these details automatically.

  6. Reliable handshakes and handshakes: TCP uses a three-way handshake to establish a connection, ensuring that both parties are ready to send and receive data. At the end of the communication, TCP uses four waves to close the connection and ensure that both parties can transmit all data intact.

  7. End-to-end communication: TCP is an end-to-end protocol that is responsible for sending data transfers between applications from one end to the other. It hides the details of the underlying network, allowing applications to focus on data transmission and processing.                 

  8. Dependency: TCP relies on IP for data packet transmission. After TCP divides the data into segments, it encapsulates them in IP data packets and transmits them through the IP protocol.

  9. Working together: TCP and IP work together for reliable data transmission. TCP is responsible for data reliability, ordering, and flow control, while IP is responsible for routing data packets from source hosts to destination hosts and handling data packet transfer between networks.

  10. Forming the Internet protocol family: TCP and IP are the two core protocols of the Internet protocol family (TCP/IP). They are used in combination with other protocols to form the basic communication architecture of the Internet.

 About TCP's three-way handshake and four-way handshake:

SYN, ACK, SYN-ACK, and FIN are flag bits or control bits in the TCP protocol, which are used to establish and close connections. They represent the following meanings respectively:

  • SYN (Synchronize): The SYN flag is used to initiate a connection request segment, usually sent by the client to the server. When the client wants to establish a connection with the server, it will send a TCP segment with the SYN flag bit, indicating that it requests to establish a connection.

  • ACK (Acknowledgment): The ACK flag indicates confirmation. During the TCP handshake process, when the SYN message segment sent by the other party is received, the response message segment will set the ACK flag bit and confirm the previously received sequence number .

  • SYN-ACK: SYN-ACK refers to a message segment that contains both SYN and ACK flag bits, and is used to respond to a connection request. After receiving the SYN message segment from the client, the server will reply a message segment with SYN and ACK flag bits, indicating that it accepts the connection request and confirms the synchronization.

  • FIN (Finish): The FIN flag is used to close the connection. When one party decides to close the connection, it sends a segment with the FIN flag. After receiving the FIN, the receiver confirms the receipt and sends its own FIN segment as a response to complete the two-way close.

These flag bits play an important role in TCP's three-way handshake and four-way handshake. SYN and ACK are used together to ensure the establishment and synchronization of the connection; while FIN is used to close the connection and notify the other party to stop data transmission.

TCP connection establishment process (three-way handshake):

  1. The client sends a message segment with the SYN flag to initiate a connection request to the server.
  2. After the server receives the request, it replies with a message segment with the SYN-ACK flag, indicating that it accepts the connection request and confirms the synchronization.
  3. After the client receives the server's response, it sends a message segment with the ACK flag bit, indicating that it has received the confirmation from the server. At this point, the connection is established.

TCP connection closing process (four waves):

  1. One party sends a message segment with the FIN flag, indicating that it wants to close the connection.
  2. After receiving the FIN, the receiver sends a message segment with the ACK flag to confirm receipt.
  3. After the data transmission is completed, the receiver also sends a message segment with the FIN flag, indicating that it also wants to close the connection.
  4. After receiving the FIN, the sender sends a message segment with the ACK flag to confirm the receipt and complete the two-way close.

3. Introduction of UDP protocol

UDP (User Datagram Protocol) is a connectionless transmission protocol that provides a simple and unreliable data transmission service. The following is a detailed introduction to UDP:

  1. No connection: UDP is a connectionless protocol, the communication parties do not need to establish a connection before sending and receiving data. This means that UDP communication does not guarantee the reliability and order of data, and each data packet is processed independently.

  2. Lightweight: Compared with the TCP protocol, the UDP protocol is very lightweight. The UDP header is only 8 bytes, while the TCP header has at least 20 bytes. Therefore, UDP has less network overhead and has lower latency.

  3. Unreliability: UDP does not provide reliability guarantees for data transmission. It does not use acknowledgment mechanisms, retransmission mechanisms, or congestion control, nor does it guarantee the order in which data will arrive. This makes UDP more suitable for some real-time applications, such as audio and video streaming.

  4. Efficiency: Since UDP has no complex mechanism to ensure reliability, it can perform fast data transmission with minimal overhead. This makes UDP very useful in certain scenarios where efficient transmission is required.

  5. Broadcast and multicast support: UDP supports broadcast and multicast, and data can be sent to multiple target hosts at the same time. This is useful for one-to-many real-time communication, such as online gaming or video conferencing.

  6. No congestion control: UDP does not have a congestion control mechanism, which means that when the network is congested, UDP transmission may cause packet loss or increase delay. But at the same time, UDP's unreliability makes it more suitable for certain scenarios, such as sensor data transmission, where real-time performance is prioritized over reliability.

UDP (User Datagram Protocol) and IP (Internet Protocol) are two key components in the Internet protocol suite, they are closely related and work together to achieve data transmission.

  1. Packet encapsulation: UDP uses IP protocol to encapsulate and transmit data packets. At the sending end, UDP encapsulates the data of the application program into a UDP message segment; then, UDP adds the message segment to the IP data packet, and at the same time adds necessary IP header information such as source IP address and destination IP address. Finally, the IP layer sends the entire IP packet out into the network.

  2. IP address location: UDP relies on the IP protocol to address and locate the receiver. Each host has a unique IP address, and UDP uses these addresses to determine the target host to send data to and deliver the data packet to the correct destination.

  3. Protocol level: UDP is at the transport layer, while IP is at the network layer. UDP is responsible for providing simple, connectionless data transmission services, and handling the segmentation and reassembly of datagrams; while IP is responsible for routing data packets from source hosts to destination hosts, and handling issues such as data packet transfer, routing selection, and addressing between networks.

  4. Complementary relationship: UDP and IP complement each other. UDP provides protocol header information for data transmission, such as source port number and destination port number, to identify communication between applications; while IP is responsible for providing underlying routing and addressing function to ensure that the data packets can reach the target host correctly.

HTTP (Hypertext Transfer Protocol) and HTTPS (Hypertext Transfer Protocol Secure) are protocols for transferring data over the network. They are described in detail below:

HTTP:

  1. Unencrypted transmission: HTTP is a stateless protocol for transmitting hypertext data between clients and servers. It transmits data in clear text and provides no encryption protection, making it vulnerable to man-in-the-middle attacks or data tampering.

  2. The default port is 80: HTTP uses port 80 of the TCP protocol for communication by default.

  3. No connection: Each request is independent, that is, after the client sends the request and waits for the response, the connection will be closed. This means that the server cannot remember previous requests.

  4. Plaintext transmission: HTTP data transmission is in plaintext, including URL, request header, and response content. This puts the confidentiality of data at risk, such as user login information or sensitive data could be stolen.

HTTPS:

  1. Encrypted transmission: HTTPS is a protocol that securely encrypts HTTP by using the SSL (Secure Sockets Layer) or TLS (Transport Layer Security) protocol. It uses encryption algorithms to protect the confidentiality of data and prevent data from being eavesdropped or tampered with.

  2. The default port is 443: HTTPS uses port 443 of the TCP protocol for communication by default.

  3. Security verification: HTTPS uses digital certificates to verify the identity of the server. This ensures that communication between client and server is trusted and prevents man-in-the-middle attacks.

  4. Trusted connection: HTTPS encrypts and decrypts data by establishing a secure encrypted tunnel using the SSL/TLS protocol. This makes the data safe from the risk of eavesdropping and data tampering during transmission.

  5. Performance impact: Since the encryption and decryption process requires computing resources, HTTPS will increase some additional performance overhead compared to HTTP. However, this gap is decreasing as hardware and protocols continue to improve.

Guess you like

Origin blog.csdn.net/weixin_44979308/article/details/131549187