Telecommunication
Three elements:
- IP: The address of the device on the network
- Port: the unique identification of the application in the device
- Protocol: connect client and server; rules for data transmission in the network
IP address: Internet Protocol address
- IPv4: 4-byte dotted decimal 192.128.1.250
- IPv6: 32 bytes hexadecimal
Use ipconfig
to view the computer's IP address:
IP domain name:
Use the domain name to represent the IP address, because the IP address is not easy to remember. For example: https://blog.csdn.net/
There will be a DNS server in the computer to convert the domain name into an IP address. If it is the first time to access a new domain name, it will access the operator's server to obtain the IP address
The IP address is divided into public network IP and internal network IP. That is, the IP that can connect to the Internet; the LAN IP can only be used within the organization
The beginning of 192.168. is the common LAN IP address: range: 192.168.0.0~192.168.255.255
Special IP address: 127.0.0.1 or localhost represents the local address
InetAddress class
An IP address-related InetAddress class is provided in JDK. This class is used to encapsulate an IP address and provides a series of methods related to IP addresses. Next, some common methods in the InetAddress class are listed:
method declaration | Functional description | |
---|---|---|
InetAddress getByName(String host) | Get the IP address of the given host name, the host parameter indicates the specified host | |
InetAddress getLocalHost() | get localhost address | |
String getHostName() | Get the hostname of the local IP address | |
boolean isReachable(int timeout) | Determine whether the specified IP address can be accessed within a limited time | |
String getHostAddress() | Get the raw IP address in string format |
port:
Marks an application running on a computer device, specified as a 16-bit binary,