Feature: IP address port number Transfer Protocol
Packagecom. Train;Importjava.net.InetAddress;Importjava.net.InetSocketAddress;Importjava.net.UnknownHostException; Public classNetTest { Public Static voidMain (string[] args)throwsunknownhostexception{/**the =========== IP address is encapsulated as a InetAddress object ============*/ //This class represents an Internet Protocol (IP) address//obtain an IP object by using the static method of the InetAddress class: /**get loopback ip inetaddress ialoopback = inetaddress.getloopbackaddress (); * Get the native IP inetaddress ialocalhost = inetaddress.getlocalhost (); * Get IP * static inetaddress getlocalhost () based on hostname to return local host. * Static inetaddress[] Getallbyname (String host) returns an array of its IP addresses, based on the name service configured on the system, given the host name. * Static inetaddress getbyaddress (byte[] addr) Returns the InetAddress object given the original IP address. * Static inetaddress getbyaddress (String host, byte[] addr) creates inetaddress based on the host name and IP address provided. * Static inetaddress Getbyname (String host) determines the IP address of the host in the given host name. * * Obtained InetAddress class object, which encapsulates a non-static method to obtain the hostname and IP address **/inetaddress Ialocalhost=Inetaddress.getlocalhost (); System.out.println (Ialocalhost.tostring ()); System.out.println (Ialocalhost.gethostname ()); System.out.println (Ialocalhost.gethostaddress ()); System.out.println ("------------------"); InetAddress ia= Inetaddress.getbyname ("www.baidu.com"); System.out.println (Ia.gethostname ()); System.out.println (Ia.gethostaddress ()); System.out.println ("------------------"); //TCP: Connection-oriented-reliable-three-time handshake /*three-time handshake establish connection: Is it? In! I know you're here! *///UDP: For non-connected---unreliable, fast}}
Java Fundamentals-Network programming