From: http://blog.jobbole.com/74795/
Some time ago I made a development, involving network programming, and the development process was quite smooth, but I always felt a bit confused after the task was completed. The main reason is that you are not familiar with network protocols and are not clear about some concepts. Later, I spent some time learning about these network protocols. Now I have a preliminary understanding of the TCP/IP network protocol. Here I will summarize my understanding of the network protocol, deepen your impression.
To communicate with two computers, they must abide by common rules, just like two computers must use the same language. A person who only understands English cannot communicate with a person who only understands Chinese because there is no common language (rule. The common rule for communication between two computers is the network protocol.
So who will develop this network protocol?
The International Organization for Standardization (ISO) defines the basic framework of network protocols, known as the OSI model. There will be a lot of content to develop communication rules. For example, you need to consider how computer A finds computer B and whether computer A needs to provide feedback when sending information to computer B, what is the format of the data transmitted by computer A to computer B? The content is too much and too complex. Therefore, the OSI model divides these communication standards into layers, and each layer solves the problem of a category, which makes standard formulation less complex. The layer-7 standard models developed by the OSI model are: application layer, presentation layer, Session Layer, transmission layer, network layer, data link layer, and physical layer.
Although the International Organization for Standardization has developed such a network protocol model, the network protocol used by Internet communication is TCP/IP.
TCP/IP is a protocol family, which is also divided by layers. Four layers: application layer, transmission layer, interconnection network layer, and network interface layer. What is the difference between the TCP/IP protocol and the OSI model? The OSI network protocol model is a reference model, and the TCP/IP protocol is a de facto standard. The TCP/IP Protocol references the OSI model, but it does not strictly follow the layer-7 criteria defined by OSI, but only divides layer-4. I think this will be simpler, when too many layers are divided, it is difficult to tell which level a protocol belongs. The TCP/IP protocol does not conflict with the OSI model. The application layer protocol in the TCP/IP protocol corresponds to the application layer, presentation layer, and Session Layer in the OSI. Just like the former Ministry of Industry and the Ministry of Information Industry, there is only one department in the Ministry of Industry and Information Technology after the implementation of the big ministry, but this department still has to do the same thing as the previous two departments, essentially, there is no big difference. There are two important protocols in TCP/IP. The TCP protocol at the transport layer and the IP protocol at the Interconnection layer are represented by the two protocols to name the entire protocol family, the TCP/IP Protocol refers to the entire Protocol family.
TCP/IP protocols are divided into four layers, but we do not need to understand all layers of protocols. I think it is enough to focus on the protocols at the application layer and transport layer. Take sending an email as an example. A sends an email to B. A cares about the format used to write the content to B (Application Layer content), whether to send a registered letter or a ping mail (Transport Layer content ), however, a does not care about the route used in the mail transmission process. How does a postman deliver a mail to B (the interconnection network layer and network interface layer ).
First, let's talk about the transport layer. The transport layer has multiple protocols, but most of them are TCP and UDP. The difference between the two rules is that the TCP protocol requires feedback from the receiver, and the UDP protocol does not need feedback from the receiver. TCP is like a registration letter. After computer A sends a message to computer B, you need to get feedback from computer B so that computer A can know whether computer B has received the message. UDP is like a normal mail. After computer A sends a message to computer B, computer B does not send a token to computer A. After computer A sends the message, it does not know whether computer B has received the message. Therefore, TCP transmission is more reliable than UDP transmission, but TCP transmission is less efficient than UDP. As for the specific transfer method selected during the transfer process, specific problems need to be analyzed. In the process of unreliable network transmission, select TCP transmission mode. You can use the UDP mode to increase the transmission rate if you are concerned about efficiency or do not care about transmission errors.
There are many protocols at the application layer. Each Protocol represents a type of service. HTTP protocol, World Wide Web service. FTP protocol, file transfer service. POP3, mail service, and soap WebService.
When I understood the TCP/IP protocol, I encountered three puzzles.
1. What is socket?
I have heard about socket programming before, and some also talk about socket programming. When I searched for socket information, I found that socket refers to a connection and socket refers to a terminal. Let's use a telephone call as a metaphor. If a and B are talking, does socket mean the connection line between A and B, or is it the telephone terminal )?
I understand that socket is an endpoint in a connection. Each communication (connection), A, and B, all have a socket. A socket corresponds to a connection.
2. Does the HTTP protocol belong to the application layer or transport layer?
The HTTP Hypertext Transfer Protocol sounds like a transport layer protocol. But as we all know, HTTP and FTP are both application-layer protocols. I was wondering how to get such a misleading name from the application-layer protocol. When you are not familiar with the TCP/IP protocol, it is easy to misunderstand and wonder. Later, I found the following on the Wiki:
HTTP Chinese Translation
HTTP is translated as "Hypertext Transfer Protocol" in mainland China because "transfer" has the meaning of "transmission" in Chinese. However, according to Dr. Roy Fielding's essay [1] (6.5.3), the author specifically emphasizes that "transfer" represents "(state) transfer (representational state transfer) instead of transport ). Therefore, the introduction of the Chinese translation "Hypertext Transfer Protocol" reflects this misunderstanding. The original translated name should be "Hypertext Transfer Protocol ".
This passage relieved my doubts. HTTP is of course an application layer protocol.
3. Can soap be transmitted over HTTP?
In the process of understanding the SOAP protocol, we can see that soap can be transmitted through TCP, UDP, and HTTP. This is a confusing description. After reading this sentence, I will feel how HTTP is tied with TCP and UDP? Does HTTP still belong to the transport layer protocol? In addition, with the problem of translating HTTP Chinese characters, the name sounds like a transport layer, and beginners start to grow their heads again.
In fact, HTTP is an application-layer protocol, which can be unsuspected. Now we have a new problem. Both soap and HTTP are application-layer protocols. How can we say that soap can be transmitted over HTTP? Can application-layer protocols be transmitted using application-layer protocols?
I checked the materials. This is the case. After soap serializes the information in XML, it then uses the HTTP protocol to package and transfer the information. The transfer method is TCP or UDP. A metaphor is easy to understand. TCP and UDP are both roads. TCP is considered as a general road, UDP expressway, and soap and HTTP are both cars, so both soap and HTTP can run on TCP and UDP. Soap can be transmitted over HTTP. In reality, soap is a car, HTTP is a car truck, and soap information is loaded into HTTP before being transported, of course, the path is TCP or UDP.
Soap can be transmitted over the HTTP protocol. This sentence is not accurate. It is more accurate. The first statement is that soap information can be packaged over HTTP and transmitted over TCP or UDP.