20165337 ninth week study summary

study notes

The URL class is an important class in the java.net package. The URL object contains three parts of information: protocol, address and resource. The application program that uses the URL to create the object is called the client program.

构造方法:public URL(String protocol,String host,String file) throws MalformedURLException InetAddress或用public URL (String spec) throws MalformedURLException

The URL object can call the InputStream openStream() method to return an input stream that points to the resource contained in the URL object. The resource information on the server can be read into the client through this input stream.

There are two ways to represent the address of the host on the Internet: 1. Domain name, such as www.tsinghua.edu.cn 2. IP address, for example: 202.108.35.210

You can use the static method getByName(Strings) of the InetAddress class to pass a domain name or IP address to the method's parameter s

An IP address identifies a computer on the Internet, and a port number identifies a process (program) that is running on the computer. The port number is specified as a 16-bit integer between 0 and 65535.

The combination of source IP address and destination IP address and source port number and destination port number is called a socket

In socket communication: There are two basic principles:
(1) The server should start a dedicated thread, and establish a connection with the client's socket in this thread.
(2) Since the input stream of the socket may block when reading information, both the client and the server need to read information in a separate thread.

Script screenshot

code upload

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325065183&siteId=291194637