JAVA notes: Java Network Programming (1) IP and InetAddress,
Java supports the development of the network communication system. It mainly provides two communication protocols:
TCP: reliable transmission protocol, which uses three-way handshake to complete communication
UDP protocol: Unreliable transmission protocol, which is not necessarily received by the receiver during transmission
Java contains all the network program development classes in the java.net package.
IP address related knowledge belongs to the computer network content, related Introduction: http://baike.baidu.com/link? Url = MmVDEtnaE5l2iT1-FW0WEp22g0nELwHIWd1yN0H0fah896wPlfJR2zk9x5JZd9BT956uao0vSrTBE56qv_4S9q
The Inetaddress class mainly represents the IP address. This class has two sub-classes: Inet4address class and Inet6address class. One Class represents the IPV4 protocol, and the other class represents the IPV6 protocol.
Common Inetaddress methods:
Instance:
Import java.net. inetAddress; public class InetAddressDemo {public static void main (String args []) throws Exception {// All exceptions throw InetAddress locAdd = null; InetAddress remAdd = null; locAdd = InetAddress. getLocalHost (); // obtain the local remAdd = InetAddress. getByName ("http://www.baidu.com/"); System. out. println ("local IP Address:" + locAdd. getHostAddress (); System. out. println ("Baidu IP Address:" + remAdd. getHostAddress (); System. out. println ("local availability:" + locAdd. isReachable (5000 ));}};