Java is a language on the Internet, which provides support for network applications from the language level, programmers can easily develop common network applications.
Java class libraries provide network, the network connection can be painless, the underlying network details are hidden in the Java native installation system, controlled by the JVM. And Java implements a cross-platform network library, programmers are faced with a unified network programming environment.
Network programming purposes: direct or indirectly through a network protocol for data exchange with other computers, to communicate.
Network Programming There are two main issues: how to accurately locate one or more hosts on the network; specific applications on the host by the host how to find the data transmission reliably and efficiently
1.1 Overview of network communications elements
IP and port number
Network communication protocol
1.2 How to communicate with each other hosts in the network
Communicating parties address IP port number
Certain rules (ie: there are two sets of network communication protocol reference model) of the OSI reference model: the model too idealistic, could not be widely promoted on the Internet TCP / IP reference model (or TCP / IP Protocol): the de facto international standard.
Network communication protocol
data transmission:
2. IP and port number
2.1 InetAddress class
Hosts on the Internet address expressed in two ways: domain name (hostName): www.atguigu.com IP address (hostAddress): 202.108.35.210
InetAddress class represents a major IP address, two sub-categories: Inet4Address, Inet6Address.
InetAddress class object contains a host address Internet domain names and IP addresses: www.atguigu.com and 202.108.35.210.
Domain name easy to remember, when entering a host when connecting to a network domain, the domain name server (DNS) is responsible for translating domain names into an IP address in order to establish a connection and the host. -------DNS
InetAddress class does not provide a common constructors, but provides the following several static methods to obtain Example InetAddress
InetAddress provides the following several common methods
public String getHostAddress():返回 IP 地址字符串(以文本表现形式)。
public String getHostName():获取此 IP 地址的主机名
publicbooleanisReachable(int timeout):测试是否可以达到该地址
3. Network Protocol
Network communication protocols in computer networks for communication must be some conventions, i.e. the communication protocol, standard rate for the transmission code, the code structure, the transmission control step, an error control.
Problem: Network protocol too complicated computer network communication involves a lot of content, such as specifying the source and destination addresses, encryption and decryption, compression and decompression, error control, flow control, routing control, how to implement such a complex network protocol it?
Thinking communications protocol layering in the development agreement, the complex components broken down into a few simple ingredients, and then composite them together. The most common method is complex hierarchical manner, i.e., the interlayer may be in communication with the upper layer can call the next layer, the next layer with the relationship does not occur. Each layer independently of each other, conducive to the development and expansion of the system.