I. Writing at the beginning
Hello everyone, Brother Build is back! Stop more about 2 months long, before a period of time to write a novel to go, and then because the company live too much, cattle and horses dry too much commitment, pulled down the blog update, the National Day, a rare idle, ready to return to their old jobs.
Roughly looked over the content of the previous update, has been written to the IO part of Java, as a network transmission of a major focus of knowledge, IO is critical, and in order to better understand and use IO, we have to extend today to talk about network programming in Java. In fact, this sentence is not too strict, network programming is not unique to Java, all rely on the Web side of the programming language, or applications are inseparable from the network programming.
II. Foundations of network programming
OK, no more talk, let's get straight to the point, to learn about network programming, before we start learning, we should understand our daily life are inseparable from the Internet and peripheral products (routers, Web sites, cell phones, computers) and so on.
2.1 Computer networks
Computers are very familiar to us, before multiple networked computers, we can chat, video, e-mail exchanges, but also through different media platforms for interoperability, all the users online between the devices, like a large network connected, interoperability, which is the computer network!
As shown above, it is a generalized network topology sketch that encapsulates our current Internet world in a very visual and easy to understand way. Among them.user equipmentSuch as cell phones, computers these are used to access web resources such as watching dramas, brushing up on news, andnetwork switchOn the other hand, it is the bridge that allows the phone to access the Internet and is used to connect the devices on the LAN to the router, while therouter (computing)The main work is to realize the routing between different networks, which can be connected to the Internet, and in order to prevent the intrusion of some for authorized access to the device, the network of the device are equipped with afirewalls, which is used to intercept unauthorized requests; andthe Internetand, in turn, a network of information resources that are globally interoperable with each other.server (computer)Needless to say, processing and storage stations for hosting web applications and data.
So, see here we have such a question, different countries and regions of the world there are different LANs, following different network protocols, how to achieve global interoperability of the Internet? The great pioneers have long considered this point, therefore, the earliest development of the specification of the gang, the interconnection of the global protocol specification, that is, the TCP / IP protocol, the following when we talk about the protocol will say.
2.2 IP
For IP, we are very familiar with, we are in the daily process of surfing the Internet, said the URL, in fact, the main is this IP (Internet Protocol), the Chinese translation for the International Interconnection Protocol. It is like an identity card number, the only identification of a network interface, any computer connected to the Internet as long as the computer has an IP address.
at the present timeIPconsist ofIPv4cap (a poem)IPv6,on account ofv4version adopted32bit address,the more you count42Billions of addresses,at the present time已经用尽,That's why the launch of thev6releases,adoption128bit address,340万亿亿亿Billions of addresses,treat (sb a certain way),You read that right.,2(used form a nominal expression)128That's how many addresses there are.,这个数字是人类灭绝了都用不完(used form a nominal expression)。
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)