20165305 Su Zhenlong's study summary of the ninth week of "Java Programming"

Chapter 13 Java Network Programming

Learn to understand the classes used in network programming and understand the important role of the URL, Socket, InetAddress, and DatagramSocket classes in network programming.
Applications that use URLs to create objects are called client programs.
Create a URL object with the public URL(String spec) throws MalformedURLException constructor.
By calling the InputStream openStream() method to return the input stream pointing to the resource contained in the URL object, the resource information on the server can be read into the client. The
network socket is a connected communication based on the TCP protocol. The server establishes a ServerSocket object, which is responsible for waiting for the client to request to establish a socket connection, and the client establishes a Socket object to send a socket connection request to the server.
UDP-based communication transmits information faster than TCP-based communication, but does not provide reliability guarantee
design When broadcasting a datagram network program, the hosts that want to broadcast or receive the broadcast must be added to the same class D address.
Using RMI allows an application on the JVM to request a method call on an object located on another JVM on the network

URL class

The URL class is an important class in the java.net package.
A URL object contains three basic information: protocol, address and resource
protocol: it must be a protocol supported by the Java virtual machine where the URL object is located. Commonly used are: Http, Ftp , File protocol, specified by the parameter protocol
Address: must be a valid IP address or domain name that can be connected, specified by the parameter host
Resource: can be any file on the host, specified by the parameter file

InetAddress class

There are two ways for a host to represent an address on the Internet
Domain name
IP address

socket

It is a network communication based on the TCP protocol.
Client socket
object establishment method: use the Socket class
Socket construction method: Socket (String host, int port)
multi-threading technology
When the server receives a client's socket, it will start a A thread dedicated to this client
Socket communication fundamentals

UPD datagram

The basic mode of communication based on UPD
Send data packets
Pack: use the DatagramPacket class
Send: use the constructor DatagramSocket() to create an object
Receive data packets
Use the constructor DatagramSocket(int port) to create an object
Use the method receive(DatagramPacket pack) to receive data packets

broadcast datagram

Class A address: a<128, then bcd represents the host
Class B address: 128<=a<192, then ab represents the network address, cd represents the host address
Class C address: a>=192, abc represents the network address, d represents the host Address
Class D address: 224.0.0.0~224.255.255.255 is a reserved address
. Hosts that want to broadcast or receive broadcasts must join the same class D address

code hosting

Script screenshot


Summary of last week's mistakes

This week's puzzle roundup

In this week's experiment, we need to refactor the program code in IDEA, but I don't know how to refactor, so I checked it online, and the following are the shortcut keys for refactoring.
Rename files, methods, properties, etc. (rename): SHIFT+F6
Extract the current selection as a variable (extract variable): CTRL+ALT+V
Extract the current selection as a property (extract field): CTRL+ALT+F
Extract the current selection as a constant (extract constant): CTRL+ALT+C
to extract the current selection as a method (extract method): CTRL+ALT+M
to extract the current selection as a method parameter (extract parameter): CTRL+ALT+P
to refactor classes and methods (change signarture) : CTRL+F6
to extract code blocks into if, try and other structures (surround with): CTRL+ALT+T
to create module files, etc. (new): CTRL+ALT+N
to create test cases (test): CTRL+SHIFT+T
to repeat Refactor for this: CTRL+T

Guess you like

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