1. Basic concepts

** network: ** computer interconnection line into a network; Networking purpose: Communicate with each other and share resources

Network classification: according to the distance, computer networks are divided into LOCAL area network, metropolitan area network, Internet

**IP address: the address of the host in the ** network (globally unique, current IP4 — running out — IP6 will be enabled in the near future)

Domain name: alias of an IP address. The actual host is accessed using a domain name address because the IP address is difficult to remember and understand. A domain name server is required to map the domain name to the corresponding IP address and then access a host.

** Protocol: ** The rules for communication between computers are called protocols (seven-layer protocol: Back one)

Seven layer protocol: * * * * the physical layer, data link layer, network layer (IP), the transport layer (TCP) – session layer, presentation layer – the application layer (remember)

TCP requires a three-way handshake during transmission

2. Network commands

Ping IP address or domain name address

Ipconfig: Displays the local IP address information

.

3. Network programming

Related components designed by SUN for network programming are put into: java.net.* package

The IP address class

InetAddress ip = InetAddress.getLocalHost();
ip = InetAddress.getByName("www.lanqiao.cn");
System.out.println(ip.getHostName() +" --  " + ip.getHostAddress() )
Copy the code

URL: Uniform Resource Locator (URL) A major method of web crawlers

String spec ="http://dasai.lanqiao.cn/pages/dasai/about_ours.html"; URL url = new URL(spec); // Get resource information -- essentially read the information of a document on a host in the network; InputStream in = url.openStream(); // Get a byte stream; OutputStream out = new FileOutputStream("E:\\about_ours.html"); byte[] buff =new byte[1024*4]; int len = -1; while((len = in.read(buff))! =-1) { out.write(buff, 0, len); } out.close(); in.close();Copy the code
4. Socket programming [core]

Socket: IP + port called socket (Socket programming is the core of network programming)

Socket programming is divided into: one is based on TCP socket programming (connection-oriented), the other is based on UDP socket programming (connection-oriented).

In the java.net package, provides several core components: ServerSocket | Socket | DatagramSocket | DatagramPacket