InetAddress
InetAddress is used to represent an IP address, and a inetaddress represents an IP address
How to create an InetAddress object, Getbyname (String host), can be an IP, or it can be a domain name
GetHostName (): Gets the domain name corresponding to the IP address
Gethostaddress (): Get IP Address
InetAddress byname = Inetaddress.getbyname ("www.baidu.com"); // Establish an IP address String hostName = Byname.gethostname (); // get the domain name of the IP address String address = byname.gethostaddress (); // Get IP Address System.out.println (hostName); SYSTEM.OUT.PRINTLN (address);
Socket
Using sockets to develop Web applications has long been widely adopted as a de facto standard.
A socket on both ends of the communication is the endpoint of the communication between the two computers.
Network communication is actually the communication between sockets
The socket allows the program to treat the network connection as a stream, and the data is transmitted via IO between two sockets.
Java Network programming