20165322 Wang Yao Good-java 9th week homework

Source: Internet
Author: User

Textbook Knowledge Summary 13th Chapter Java Network Programming
    1. 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: must be a protocol supported by the Java Virtual machine where the URL object resides, commonly used: Http, FTP, file protocol, specified by 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
    • Construction method
      • Public URL (String spec) throws Malformedurlexception
      • Public URL (String protocol,string host,string file) throws Malformedurlexception
    • Call the InputStream OpenStream () method to return an input stream
    1. InetAddress class
    • Two ways that hosts represent addresses on the Internet
      • Domain name
      • IP Address
    • Get address
      • Get host address on Internet: getbyname (String s)
      • Get Local Machine Address: getlocalhost ()
    1. Sockets
    • TCP protocol-based network communication
    • Client sockets
      • Object Creation method: using the Socket class
      • Socket construction Method: Socket (String host,int port)
    • ServerSocket object and server-side sockets
      • Construction method: ServerSocket (int port)
    • Use the method accept () to connect the client socket to the server-side socket
try{ Socket sc = serverForClient.accept();}catch(IOException e) {}
    • Sockets use the Close () method to close a socket connection after communication is complete
    • Multithreading Technology
      • When a client-side socket is received by the server, a thread is started that is dedicated to the customer service
    • Basic principles of socket communication
      • The server should start a dedicated thread that establishes a connection to the client's socket in that thread
      • Both the client and the server need to read information in a separate thread because the socket's input stream can be blocked while reading information
    1. UPD Data Report
    • Basic mode based on UPD communication
      • Package data to a destination
      • Receive sent packets and view content
    • Sending a packet
      • Packaging: Using the Datagrampacket class
DatagramPacket(byte data[],int length,InetAddtress address,int port)
DatagramPack(byte data[],int offset,int length,InetAddtress address,int port)
    • Send: Create an object using the construction method Datagramsocket ()
    • Receiving packets
      • Create an object using the constructor method datagramsocket (int port)
      • Receive packets using method receive (Datagrampacket pack)
    1. Broadcast Data Report
    • Class A address: a<128, the B.C.D represents the host
    • Class B Address: 128<=a<192, the A.B represents the network address, C.D represents the host address
    • Class C Address: A>=192,A.B.C represents the network address, and D indicates 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 be joined to the same class D address
    1. RMI is a distributed technology that allows an application on one virtual machine (JVM) to invoke an object method on another JVM on the network using RMI
Problems encountered and their solutions
    • Occurs when you run the first code of this chapter

      WORKAROUND: Package Two programs separately in the same folder, enter javac -encoding gbk Example13_1.java them, and then compile and run them successfully.

Code Hosting

Last week's summary of wrong questions
    1. Analytical:

    2. Parsing: When the Main method does not create another thread, the JVM ends the Java application when the main method returns, and when the main method creates another thread, the JVM ends the Java application until all threads are finished.

    3. Parse: C: The previous entity becomes "junk" and is not collected by the garbage collector. D: When a thread enters a dead state, the thread can also call the IsAlive () method, and the return value is false.

20165322 Wang Yao Good-java 9th week homework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.