The difference between TCP/IP and Http

Source: http://www.cnblogs.com/renyuan/archive/2013/01/19/2867720.html
TPC/IP protocol is a transport layer protocol, which mainly solves how data is transmitted in the network, while HTTP is an application layer protocol. Mainly solve how to package data. Regarding the relationship between TCP/IP and HTTP protocols, the network has a relatively easy-to-understand introduction: "When we transmit data, we can only use the (transport layer) TCP/IP protocol, but in that case, if there is no application layer, it cannot be recognized. Data content, if you want to make the transmitted data meaningful, you must use application layer protocols, there are many application layer protocols, such as HTTP, FTP, TELNET, etc. You can also define application layer protocols yourself. WEB uses HTTP protocol as application layer protocol to encapsulate HTTP text information and send it over the network using TCP/IP as the transport layer protocol." The

  term TCP/IP stands for Transmission Control Protocol/Internet Protocol and refers to a family of protocols. "IP" stands for Internet Protocol, which is used by TCP and UDP to transfer packets from one network to another. Think of IP as a kind of highway that allows other protocols to drive on it and find exits to other computers. TCP and UDP are "trucks" on the highway, and the cargo they carry are protocols like HTTP, file transfer protocol FTP, etc.
    As you should understand, TCP and UDP are transport layer protocols used by the likes of FTP, HTTP and SMTP. While both TCP and UDP are used to transport other protocols, they have one significant difference: TCP provides guaranteed data transfer, while UDP does not. This means that TCP has a special mechanism to ensure that data is passed from one endpoint to another without error, while UDP does not provide any such guarantee.
    HTTP (Hypertext Transfer Protocol) is a protocol that uses TCP to transfer information between two computers (usually a web server and a client). The client uses a web browser to initiate an HTTP request to the web server, and the web server sends the requested information to the client.
  The following diagram attempts to show where the different TCP/IP and other protocols fit into the original OSI model:

7 Application layers such as HTTP, SMTP, SNMP, FTP, Telnet, SIP, SSH, NFS, RTSP, XMPP, Whois, ENRP
6 Presentation layer such as XDR, ASN.1, SMB, AFP, NCP
5 Session layer such as ASAP, TLS, SSH, ISO 8327 / CCITT X.225, RPC, NetBIOS, ASP, Winsock, BSD sockets
4 Transport layer such as TCP, UDP, RTP, SCTP, SPX, ATP, IL
3 Network layers such as IP, ICMP, IGMP, IPX, BGP, OSPF, RIP, IGRP, EIGRP, ARP, RARP, X.25
2 Data link layers such as Ethernet, Token Ring , HDLC, Frame Relay, ISDN, ATM, IEEE 802.11, FDDI, PPP
1 Physical layer such as line, radio, fiber, pigeon


1, several important concepts of HTTP protocol
1. Connection: The actual circulation of a transport layer , which is built between two applications that communicate with each other.
2. Message: The basic unit of HTTP communication, consisting of a structured sequence of octets and transmitted over a connection.
3. Request: A request message 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: A message returned from the server including the version of the HTTP protocol number, the status of the request (eg "successful" 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 from a service resource, which may be enclosed in a request or response message. An entity includes entity header information and the entity's own content.
7. Client (Client): An application that establishes a connection for the purpose of sending a request.
8. User agent: Initializes a requesting client. They are browsers, editors or other user tools.
9. Server: An application that accepts connections and returns information to requests.
10. Origin server: A server on which a given resource can reside or be created.
11. Proxy: An intermediate program that can act as a server or a client to establish requests for other clients. Requests are passed to other servers either internally or via possible translation. Before sending a request message, a proxy MUST interpret and if possible rewrite it.
A proxy often acts as a client-side portal through a firewall, and a proxy can also serve as a helper application to handle requests through protocols that are not fulfilled by a user agent.
12. Gateway: A server that acts as an intermediary for other servers. Unlike a proxy, a gateway accepts requests as if it were the origin server for the requested resource; the requesting client is unaware that it is dealing with a gateway.
The gateway often acts as a server-side gateway through the firewall, and the gateway can also act as a protocol translator to access resources stored on non-HTTP systems.
13. Channel (Tunnel): It is an intermediary program that acts as a relay between two connections. Once activated, the channel is considered not to be part of HTTP communication, although the channel may have been initiated by an HTTP request. The channel disappears when both ends of the connection being relayed are closed. Channels are often used when a Portal must exist or an Intermediary cannot interpret relayed communications.
14. Cache: Local storage of response information.


2. Send request After
opening a connection, the client sends the request message to the stop port of the server to complete the action of making the request.
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 number CRLF
method = GET | HEAD | POST | extension method
URL = protocol name + host name + directory and file name The method in the
request line describes the action that should be performed in the specified resource. The commonly used methods are GET, HEAD and POST. The corresponding GET results of different request objects are different, and the corresponding relationship is as follows: the result of
the object GET
The content of
the file The program execution result of the program The
database query query result
HEAD?? Ask the server to find the meta information of an object, not the object itself .
POST?? transmits data from the client to the server, and the POST method is used when asking the server and CGI for further processing. POST is mainly used to send the content of FORM in HTML text for CGI program to process.
An example of a request is:
GEThttp://networking.zju.edu.cn/zju/index.htmHTTP/1.0 networking.zju.edu.cn/zju/index.htmHTTP/1.0 Header information is also called meta-information, that is, information of information, using meta-information Conditional requests or responses can be implemented.
The request header tells the server how to interpret the request, mainly including the data type, compression method and language that the user can accept.
Entity header?? Entity information type, length, compression method, last modification time, data validity period, etc.
Entity?? The request or response object itself.
3. Send a response After the
server has processed the client's request, it will 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 number status code reason description The
status code indicates the response type
1×× reserved
2 ×× indicates that the request is successfully received
3×× To complete the request, the client needs to further refine the request
4×× Client error
5×× Server error The information in the
response header includes: service program name, notifying the client that the requested URL requires authentication, and the requested resource When can it be used.
4. Close the connection Both
client and server can end the TCP/IP conversation by closing the socket

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326870464&siteId=291194637