Different aspects of network communication are divided into different layers. Each layer represents a different abstraction layer between the physical hardware and the transmitted information. Theoretically, each layer only communicates with the layer next to it. By layering the network, you can modify or even replace the software of a certain layer. As long as the interface between the layer and the layer remains unchanged, it will not affect other layers. For example:
Shows the possible protocol stacks in your network. Although the intermediate layer protocol on the internet is quite stable today, the protocols on the upper and lower layers have changed a lot. Some hosts use Ethernet, some use WiFi, some use PPP, and some use other protocols. Similarly, the protocol used at the top layer of the stack depends entirely on the program running on the host. The key is that from the perspective of the top layer of the stack, the underlying protocol is not important, and vice versa. From the bottom layer, it does not matter what the top layer protocol is. This layered model implements the decoupling of application protocols, network hardware physical properties, and network connection topology.
There are several different layered models that suit the needs of specific types of networks. This book uses a standard layer-4 TCP/IP model for the Internet, such:
In this model, applications such as Firefox run at the application layer and only talk to the transport layer. The transport layer only communicates with the application layer and the Internet layer. The Internet layer only communicates with the host network layer and transport layer, and never directly communicates with the application layer. The host network layer moves data to the host network layer of the remote system through cables, optical fibers, or other media, and then transfers the data to the application layer of the remote system step by step through the above layers.
For example, when a web browser sends a request to the Web server to obtain a web page, the browser only communicates with the transmission layer of the local client. The Transport Layer splits the request into TCP slices, adds the serial number and checksum to the data, and then passes the request to the local Internet layer. The Internet layer divides the TCP/IP into IP datagram based on the size required by the local network, and transmits the data to the host network layer for transmission through the cable. The host network layer encodes the digital data into analog signals suitable for specific physical media, and sends requests to the cable. The host network layer of the remote system at the target address can read requests from this network layer.
The host network layer of the remote system decodes analog signals into digital data and transmits the generated IP datagram to the server's Internet layer. The Internet layer simply checks whether the IP datagram is damaged. If the data has been sharded, the data is reorganized and then transmitted to the transport layer of the server. The Transport Layer of the server checks whether all data has arrived, and re-transmission is required for lost or damaged parts (this request will actually go down through the server's Internet layer, then, return to the client system through the host network layer of the server, and then return to the transmission layer of the client in the client system. Then, the transport layer retransmits the lost data through the local Internet layer and the host network layer. All of these are completely transparent to the application layer ). Once the transport layer of the server receives enough continuous data packets, it is reorganized and written into a stream, which is read by the Web server running on the application layer of the server. The server responds to this request, sends back the response through various layers of the server system, transmits the request over the Internet, and distributes the request to the Web Client.
As you can guess, the actual process is more complicated. The host network layer is the most complex, and many details are intentionally hidden. However, in 90% of the cases, Java code will work at the application layer and only need to talk to the transport layer. The other 10% of the time will be processed at the transport layer, and will talk to the application layer or the Internet layer. The complexity of the host network layer is hidden for you, which is the key to the layered model.
Tip: If you read the network literature, you may see another OSI Layer-7 network model called Open Systems intercommection Reference Model (OSI ). The OSI model is too complex for Java Network programs. The biggest difference between the OSI model and the TCP/IP model used in this book is that the OSI model divides the host network layer into the data link layer and the physical layer, and inserts the presentation layer and Session Layer Between the application layer and the transport layer. The OSI model is more general and more suitable for non-TCP/IP networks, but it is still too complex in most cases. In any case, Java Network classes only work on TCP/IP networks and always run on the application layer or transport layer.
Basic Network concept-network layering