1. Write at the beginningHello everyone, I'm back! I haven't updated for about 2 months. I was writing a novel for a while before, and then I had too much work in the company and was too devoted to it, so I fell behind in updating the blog. During the National Day holiday, I had a rare break and was ready to return to my old job. I have roughly reviewed the previous updates and have already written about Java's IO. As a key knowledge of network transmission, IO is crucial. In order to better understand and use IO, today we will extend the discussion to talk about network programming in Java. In fact, this statement is not very rigorous. Network programming is not unique to Java. All programming languages or applications that rely on the Web are inseparable from network programming. 2. The Basics of Network ProgrammingOk, let’s get straight to the point and learn about network programming. Before we start learning, we should understand the Internet and peripheral products (routers, websites, mobile phones, computers) that we cannot do without in our daily lives. 2.1 Computer NetworksComputers are very familiar to us. With multiple networked computers, we can chat, video, and exchange emails. We can also communicate with each other through different media platforms. All online user devices are connected in series like a big network, and can communicate with each other. This is the computer network! picture As shown above, it is a simplified diagram of network topology, which is very vivid and easy to understand. Among them, user devices such as mobile phones and computers are used to access network resources, such as watching TV shows and reading news, while network switches are bridges that allow mobile phones to access the Internet, and are used to connect devices and routers in the local area network. The main job of routers is to realize routing between different networks and connect to the Internet. In order to prevent some unauthorized access to intrude into devices, a firewall is set up in the network of devices to intercept unauthorized requests; and the Internet is a global information resource network that is interconnected. Servers, needless to say, are used to host network applications and data processing and storage stations. So, seeing this, we have such a question. Different countries and regions in the world have different local area networks and follow different network protocols. How can we achieve global Internet connectivity? Our great ancestors have already considered this point. Therefore, the first group of people who formulated the specifications reached a global protocol specification for the Internet, which is the TCP/IP protocol. We will talk about it when we talk about the protocol below. 2.2 IPEveryone is familiar with IP. When we surf the Internet, the web address we refer to is actually the Internet Protocol (Internet Protocol). It is like an ID card number, uniquely identifying an interface in the network. Any computer connected to the Internet only needs an IP address. Currently, IP is divided into IPv4 and IPv6. Since the v4 version uses 32-bit addresses, which is about 4.2 billion addresses, it has been used up. Therefore, the v6 version was launched, which uses 128-bit addresses and 340 trillion trillion trillion addresses. Yes, you read it right, that is 2 to the power of 128 addresses. This number is so large that it cannot be used up even if humans become extinct. A special IP address, called the local address, which is always 127.0.0.1 IPv4 (e.g. 101.302.88.22) IPv6 (e.g. 2001:0DA8:100A:0000:0000:1020:F2F3:1428) picture We can see the network information of our computer through ipconfig. In addition to the local 127.0.0.1, our computer also has an IP address. If there are multiple network cards, there will be multiple IP addresses. So how do different computers communicate with each other? The concept of "network number" is involved here. The network number is calculated by IP and subnet mask. If the network numbers between two computers are the same, it means that the two computers are in the same network and can communicate directly. If they are different, they are not in the same network and need to communicate indirectly through a router or switch, which is the gateway. 2.3 Domain NameIt is said that most of the addresses on the Internet refer to IP addresses. Many people may be surprised. For example, when we log in to Baidu, we do not enter the format of xxx.xxx.xxx.xxx, but www.baidu.com, and this combination is the domain name! We use the domain name resolution server DNS to translate the domain name into the corresponding IP address, and the client accesses the server based on the IP address. Obviously, compared to a bunch of numbers in an IP address, a domain name is easier to remember! We can use the nslookup command to view the IP address corresponding to the domain name. picture Of course, the local IP address 127.0.0.1 we mentioned above also has a corresponding local domain name: localhost picture 2.4 Network ModelFor multiple devices to share the Internet, it is not something that can be solved by just a few lines as shown in Figure 1. The internal, underlying design is very complex. In order to achieve a common standard interface on a global scale, many organizations have issued similar standard specifications. The most famous and now generally recognized one is the Open System Interconnection Reference Model (OSI; referred to as the OSI model) is a conceptual model proposed by the International Organization for Standardization. It is a standard framework that attempts to interconnect various computers into a network worldwide. The OSI model is divided into seven layers: from bottom to top: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, and application layer. picture But what we actually use on the Internet is the TCP/IP model, which does not correspond to the OSI 7-layer model, but roughly corresponds to the OSI 5-layer model. Some people also say it is a 4-layer model. It depends on you. It doesn’t matter. The main thing is to understand the process. 2.5 Commonly used protocolsIn the OSI model above, we can see that there are many network protocols corresponding to the application layer, transport layer, network layer, and data link layer. We can collectively refer to them as the TCP/IP protocol suite. Next, we will briefly introduce several important protocols:
ConclusionThat’s all for today. I will mainly introduce the basic knowledge related to network programming. In subsequent blog posts, I will further organize and refine the content required for network programming. Java Growth Plan 75 Java Growth Plan · Table of Contents#Java Growth Plan The previous article detailed the three core components of NIO, which fully explains why NIO has high performance in network IO! |
Statistics from 2016 show that the average daily ...
The hype about 5G has masked many problems. For C...
2019 saw the emergence of 5G commercial capabilit...
Last weekend, DesiVPS sent a message about the ne...
The tribe has shared information about spinserver...
We are in the midst of a great digital wave. Inno...
The way businesses run their networks has remaine...
At the HAS Analyst Conference recently, Chen Jinz...
In response to rumors that "the first tens o...
What is Link Aggregation? Link aggregation is a t...
From the issuance of 5G commercial licenses to th...
The tribe has been sharing that there are a few C...
In order to save money and reduce the use of MPLS...
On April 22, Huawei Chairman Liang Hua shared his...
PacificRack has launched the Winter Sales promoti...