The TCP/IP protocol is a transport layer protocol that mainly addresses how data is transmitted over the network, while HTTP is an application layer protocol that mainly deals with how to package the data. Regarding the relationship between TCP/IP and HTTP protocols, there is a relatively easy-to-understand introduction on the internet: “When we transmit data, we can use only the (transport layer) TCP/IP protocol, but in that case, without an application layer, the content of the data cannot be recognized. If we want the transmitted data to be meaningful, we must use application layer protocols. There are many application layer protocols, such as HTTP, FTP, TELNET, etc., or we can define our own application layer protocols. The web uses the HTTP protocol as the application layer protocol to encapsulate HTTP text information and then uses TCP/IP as the transport layer protocol to send it over the network.”
The term TCP/IP stands for Transmission Control Protocol/Internet Protocol, which refers to a suite of protocols. “IP” stands for Internet Protocol, which TCP and UDP use to transfer data packets from one network to another. Think of IP as a highway that allows other protocols to travel on it and find exits to other computers. TCP and UDP are the “trucks” on that highway, carrying cargo like HTTP, File Transfer Protocol (FTP), and others.
You should understand that TCP and UDP are transport layer protocols used by FTP, HTTP, and SMTP. Although both TCP and UDP are used to transmit other protocols, they have a significant difference: TCP provides guaranteed data transmission, while UDP does not. This means that TCP has a special mechanism to ensure that data is transmitted securely and without errors from one endpoint to another, while UDP does not provide any such guarantees.
HTTP (Hypertext Transfer Protocol) is the protocol used to transmit information between two computers (usually a web server and a client) using TCP. The client initiates an HTTP request to the web server, which sends the requested information back to the client.
The following chart attempts to show the different positions of TCP/IP and other protocols in the original OSI model:
7 | Application Layer | e.g., HTTP, SMTP, SNMP, FTP, Telnet, SIP, SSH, NFS, RTSP, XMPP, Whois, ENRP |
6 | Presentation Layer | e.g., XDR, ASN.1, SMB, AFP, NCP |
5 | Session Layer | e.g., ASAP, TLS, SSH, ISO 8327 / CCITT X.225, RPC, NetBIOS, ASP, Winsock, BSD sockets |
4 | Transport Layer | e.g., TCP, UDP, RTP, SCTP, SPX, ATP, IL |
3 | Network Layer | e.g., IP, ICMP, IGMP, IPX, BGP, OSPF, RIP, IGRP, EIGRP, ARP, RARP, X.25 |
2 | Data Link Layer | e.g., Ethernet, Token Ring, HDLC, Frame Relay, ISDN, ATM, IEEE 802.11, FDDI, PPP |
1 | Physical Layer | e.g., Lines, Radio, Fiber Optics, Carrier Pigeons |
1. Several Important Concepts of the HTTP Protocol: 1. Connection: An actual flow at the transport layer established between two communicating applications. 2. Message: The basic unit of HTTP communication, including a structured octet sequence transmitted through the connection. 3. Request: Information requested from the client to the server, including the method applied to the resource, the identifier of the resource, and the version number of the protocol. 4. Response: Information returned from the server, including the version number of the HTTP protocol, the status of the request (e.g., “success” or “not found”), and the MIME type of the document. 5. Resource: A network data object or service identified by a URI. 6. Entity: A special representation of a data resource or a reflection of a service resource, which may be enclosed in a request or response message. An entity includes entity header information and the content of the entity itself. 7. Client: An application that establishes a connection for the purpose of sending requests. 8. User Agent: The client that initiates a request. They are browsers, editors, or other user tools. 9. Server: An application that accepts connections and returns information in response to requests. 10. Origin Server: A server on which a given resource can reside or be created. 11. Proxy: An intermediary program that can act as a server or a client, establishing requests for other clients. Requests are internally translated or forwarded to other servers. A proxy must interpret and, if possible, rewrite the request before sending it. Proxies often serve as portals on the client side through firewalls, and they can also assist applications in processing requests not completed by user agents. 12. Gateway: A server that acts as an intermediary with other servers. Unlike a proxy, a gateway accepts requests as if it were the origin server for the requested resource; the client that issued the request is unaware that it is dealing with a gateway. Gateways often serve as portals on the server side through firewalls, and they can also act as protocol translators to access resources stored in non-HTTP systems. 13. Tunnel: An intermediary program that serves as a relay between two connections. Once activated, the tunnel is considered outside of HTTP communication, even though it may be initialized by an HTTP request. The tunnel disappears when the connections at both ends of the relay are closed. Tunnels are often used when a portal must exist or an intermediary cannot interpret the relayed communication. 14. Cache: Local storage of reflective information.
2. Sending a Request: After opening a connection, the client sends the request message to the server’s listening port, completing the request action. The format of the HTTP/1.0 request message is: Request Message = Request Line (General Information | Request Header | Entity Header) CRLF [Entity Content] Request Line = Method Request URL HTTP Version CRLF Method = GET | HEAD | POST | Extended Method URL = Protocol Name + Host Name + Directory and File Name The method described in the request line specifies the action to be performed on the resource, with common methods being GET, HEAD, and POST. The results corresponding to different request objects vary as follows: Object GET Result File Content of the file Program Execution result of the program Database Query result HEAD requests the server to find the metadata of a certain object rather than the object itself. POST sends data from the client to the server and is used when the server and CGI need to process further. POST is mainly used to send the content of FORM in HTML text for processing by CGI programs. An example of a request is: GET http://networking.zju.edu.cn/zju/index.htm HTTP/1.0 networking.zju.edu.cn/zju/index.htm HTTP/1.0 The header information is also known as metadata, which provides information about the information, allowing for conditional requests or responses. Request Header: Informs the server how to interpret this request, mainly including the types of data the user can accept, compression methods, and languages, etc. Entity Header: Entity information type, length, compression method, last modified time, data validity period, etc. Entity: The object of the request or response itself. 3. Sending a Response: After processing the client’s request, the server must send a response message to the client. The format of the HTTP/1.0 response message is as follows: Response Message = Status Line (General Information Header | Response Header | Entity Header) CRLF [Entity Content] Status Line = HTTP Version Status Code Reason Phrase The status code indicates the type of response: 1×× Reserved 2×× Indicates that the request was successfully received 3×× Further refinement of the request is required from the client to complete the request 4×× Client error 5×× Server error The response header information includes: service program name, notification that the requested URL requires authentication, when the requested resource will be available. 4. Closing the Connection: Both the client and server can end the TCP/IP dialogue by closing the socket.