The network is a very complicated topic. we can learn how to conduct network programming from the perspective of application. First, we need master some common protocols. Including TCP, IP, HTTP, UDP, etc. As for some routing algorithms, inter-network routing protocols, etc., it is not what we care about. For example, the wave of software products such as SDN and NFV that have emerged in recent years may not be of course our concern as application developers. If you are interested in Java and want to work on NFV, you have to learn a lot network knowledge.
When we communicate on the network, a message starts from the machine, passes through the router, the router of the operator, and then passes through the various devices on the various backbone networks of the operator, and finally arrives at us. The specified target points. This contains a lot of functions, both the pathfinding in the subnet and the pathfinding in the global network. After reaching the target machine, the operating system has to know which application to forward the message to. For example, we use QQ chat, and my pc is still on at the same time, a message arrives, the operating system has to distinguish which application does the message come from, which is very complicated.
How do network designers solve this problem? In the CCNP course of the SPOTO Club, the lecturer has already said this, a layered model. Different features are placed at different levels to simplify the problem. In fact, IP addresses are used to find paths between networks. When searching for paths between networks, the port number doesn’t make much sense. After the message reaches the destination address, the operating system forwards the message to the corresponding process according to the process corresponding to the port. The target address no longer applies to training that is forwarded within the operating system. Therefore, we can put these two kinds of data at different levels and deal with them separately, instead of a mess.
The OSI model is divided into seven layers: from top to bottom.
Application layer refers to the network operating system and specific application programs, corresponding to WWW server, FTP server and other application software.
Presentation layer Data syntax conversion, data transfer, etc.
The session layer establishes a session relationship between the two ends and is responsible for data transfer.
The transport layer is responsible for checking and repairing errors to ensure the quality of the transmission, which is where TCP works.
The network layer provides the addressing scheme, where the IP protocol works (packets)
Data link layer wraps unprocessed bit data from the physical layer into data frames
Physical layer Corresponding to physical devices (bits) such as network cables, network cards, and interfaces.
In actual development, we will not use this model, and more commonly use a four-layer model of the TCP/IP protocol family. Of course, there are other models, but for us general-purpose application developers, because they are too small, and not very valuable for learning.
Application layer: The top layer is the application layer, which is responsible for handling specific application messages. For example, Telnet, Ftp, Http, etc. Take Http as an example. Http specifies the format to be used by the browser when making a request to the server, and the format of the data used by the server to respond to the browser. As long as the rules of this format are followed, an application can establish a connection and communicate with the server.
The transport layer provides end-to-end communication primarily for applications on both hosts.
TCP provides highly reliable data communication for two hosts. The work it does involves splitting the data that the application hands over it into the appropriate network blocks, acknowledging the received packets, setting the timeout clock for sending the final acknowledgment packet, and so on. Since the transport layer provides highly reliable end-to-end communication, the application layer can ignore all of these details.
The network layer handles the activity of packets in the network, such as the routing of packets. In the TCP/IP protocol suite, the network layer protocols include the IP protocol (Internet Protocol), the ICMP protocol (Internet Control Message Protocol), and the IGMP protocol (Internet Group Management Protocol).
The link layer, also known as the data link layer, typically includes device drivers in the operating system and corresponding network interface cards in the computer. Together they handle the physical interface details with the cable (or any other transmission medium). This layer is roughly equivalent to the sum of the physical layer and the link layer in the OSI model.
How to send network messages
Let’s take a look at the specific way the message is sent. A message starts from the application layer on the left side of the figure. After the transport layer, it will be added with the data of the transport layer, and then down to the network layer. It will add the data needed for the network layer to work and reach the link layer plus Link layer data. Then, after reaching the destination, the data is parsed in order from the bottom up in the reverse order. Finally, the data obtained by the application layer on the right side is the same as the data sent by the application layer on the left side.