Basics of Network Communication-1

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

  1. IPv4: 4-byte dotted decimal 192.128.1.250

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-7yQ4izjj-1685640812058) (Network Programming Basics/image-20230601232829334.png)]

  1. IPv6: 32 bytes hexadecimal

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-BfTmHK0n-1685640812059) (Network Programming Basics/image-20230601233106265.png)]

Use ipconfigto view the computer's IP address:

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-x03SwllP-1685640812060) (Network Programming Basics/image-20230601232221601.png)]

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

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-la1HH6OA-1685640812060) (Network Programming Basics/image-20230602013127363.png)]

port:

Marks an application running on a computer device, specified as a 16-bit binary,

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-t8QawOOJ-1685640812060) (Network Programming Basics/image-20230602013104862.png)]

Guess you like

Origin blog.csdn.net/qq_43867812/article/details/130998902