20165302 ninth week study summary
URL class
- A UML object is usually created using the following constructor: public UML(Stringspec) throws MalformedurlException, which initializes a URL object with a string
The URL object can call the InputStream() method to return an input stream
InetAddress class
The method used in the InetAddress class: public String getHostName() Get the domain name contained in the InetAddress object
public String getHostAddress() Get the IP address contained in the InetAddress object
socket
- The client uses the Socket class to establish a socket object responsible for connecting to the server. The construction method is Socket (String host, int port)
- The constructor of ServerSocket is ServerSocket (int port)
Two basic principles in socket communication: 1. When the server starts a dedicated thread, it establishes contact with the client's socket in this thread. 2. Both the client and the server need to read in a separate thread. information
UDP datagram
Create a packet to be sent: DatagramPacket (byte data[],int length,InetAddress address,int port)
DatagramPacket(byte data[],int offset,int length,InetAddress address,int port)
- Using the two construction methods of DatagramPacket to create a data packet object to be sent has the following properties: 1. Contains the data specified by the data array 2. The data packet will be sent to the host whose address is address and port number is port.