Introduction to TCP/IP network protocols
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.
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.
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.
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.