Daily java: network programming

Two main problems in network programming:
(1) accurately locate one or more hosts on the network; and locate specific applications on the host
(2) how to reliably and efficiently transmit data after finding the host

To the first question: IP and port number To
the second question: provide network communication protocol: TCP/IP reference model

IP

IP: used to uniquely identify the computer (communication entity) on the Internet

Use InetAddress class to represent IP in Java

InetAddress inet1=InetAddress.getByName("www.baidu.com");
//获取本地ip
InetAddress inet2=InetAddress.getLocalHost();

IP classification method 1: IPv4 and IPv6

IPv4 consists of 4 bytes, 4 0-255, such as 192.168.0.1, a total of about 4.2 billion, 3 billion are all in North America, and were used up in early 2011.

IPv6: 128 bits (16 bytes), written as 8 unsigned integers, each integer is represented by four hexadecimal digits, and the numbers are separated by colons, such as 3ffe:3201:1401:1280:c8ff:fe4d :db39:1984

IP classification method 2: World Wide Web (public network address) and local area network (private address)

The private address starting with 192.168 is in the range of 192.168.0.0–192.168.255.255, which is specifically for internal use by the organization

Domain name: www.baidu.com is converted to IP address through DNS

The port number

The port number identifies the process that is running on the computer. :
Different processes have different port numbers , which are specified as a 16-bit integer 0-65535

Port classification:
recognized port: 0-1023. Occupied by pre-defined service communication (for example: HTTP occupies port 80, FTP occupies port 21, Telnet occupies port 23)
Registered port: 1024-49151. Assigned to user processes or applications (such as Tomcat occupies port 8080, MySQL occupies port 3306, Oracle occupies port 1521, etc.)
dynamic/private port: 49152-65535

The combination of port number and IP address results in a network socket: Socket

Network communication protocol

The communication protocol sets standards for speed, transmission code, code structure, transmission control procedures, error control, etc.

For problems: specify source and destination addresses, encryption and decryption, compression and decompression, error control, flow control, routing control.

Guess you like

Origin blog.csdn.net/weixin_49527334/article/details/113853082