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! |
What can 5G do? This is a question that everyone ...
After operators launched the "unlimited data...
As technology continues to evolve, SD-WAN (wide-a...
The Internet is everywhere and deeply affects our...
[51CTO.com Quick Translation] The new year has ar...
"5G is used to serve IoT (Internet of Things...
DogYun (狗云) launched its two-year anniversary cel...
A friend talked about cluster servers. I recently...
This article is reprinted from the WeChat public ...
[51CTO.com original article] The digital transfor...
On the afternoon of August 31, the 2021 World 5G ...
Michael Baxter says 5G will unlock the potential ...
On November 26, 2019, all IPv4 addresses were all...
[[376484]] In my work, the thing I deal with most...
If you were to pick the most used feature in Chro...