/*
* 1.IP Address: InetAddress Object
*The identity of the device in the network.
* Memory, available host name.
* Local loopback address: 127.0.0.1, hostname: localhost.
* 2. Port number: You have objects
*The identity of the different processes used to identify the logical address of the process.
*Valid ports: 0~65535, where the 0~1024 system uses or retains ports.
* 3. Transfer Protocol:
*Rules for communication.
* Common protocol: TCP,UDP.
* UDP: (QQ chat, video lessons)
* The data and the source and the target are encapsulated into a packet without the need to establish a connection.
* The size of each packet is limited to within 64k.
* Because there is no connection, it is an unreliable protocol.
* No need to establish a connection, fast.
* TCP: (QQ voice, video)
* Establish a connection to form a channel for transmitting data.
* Make large data transfers in the connection.
* Connecting via three handshake is a reliable connection protocol.
* The connection must be established and the efficiency will be slightly lower.
* 4.Socket provides a mechanism for network services.
* Sockets are available at both ends of the communication.
* Network communication is actually the communication between sockets.
* Data is transmitted via IO between two sockets.
*
*/
/*
* Network Programming:
*1 Network Model:
*OSI Reference Model:
*TCP/IP Reference Model:
* 2. Network communication elements:
* IP Address:
* Port number:
*Transport protocol:
*3. Define the communication rules:
*Language is different, communication needs rules, this rule is called protocol.
*The international organization defines the universal protocol TCP/IP.
*4. Two computer communication: Find the other IP, the data to be sent to the other side of the specified application, in order to identify these applications
* program, so to these network applications are used array to identify, in order to conveniently address this number, called "Port." Logical port.
*
*/
Import java.net.*;
public class Inetaddressdemo {
public static void Main (string[] args) throws Exception {
Get host
InetAddress I=inetaddress.getlocalhost ();
Gets the native name and IP address.
System.out.println (I.gethostname () + "---" +i.gethostaddress ());
Get the name or IP address of the other machine, the parameters inside the getbyname can make the hostname, IP address, domain name.
InetAddress ia=inetaddress.getbyname ("www.baidu.com");
System.out.println (Ia.gethostname () + "---" +ia.gethostaddress ());
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Fundamentals of Java Network programming