20165323 Java programming Nineth Week of study summary

Source: Internet
Author: User

I. Summary of teaching material content learning

URL class
1. The URL class is an important class in the java.net package, and the application that uses the URL to create the object is called the client program.
2. A URL object typically contains the most basic three-part information: protocol, address, and resource
3. How to construct the URL object:
public URL (String spec) throws MalformedURLException
public URL (String protocol, String host, String file) throws MalformedURLException
4. URL Object InvocationInputStream openStream()Method can return an input stream that points to the resource that the URL object contains.
InetAddress class
5. The InetAddress class object in the Java.net package contains the domain name and IP address of an Internet host address.
6. You can use the static method of the InetAddress class Getbyname (String s) to pass a domain name or IP address to the parameter s of the method, obtaining a InetAddress object that contains the domain name and IP address of the host address.
7. Two instance methods in the InetAddress class:
public String getHostName(): Gets the domain name contained in the InetAddress object
public String getHostAddress(): Gets the IP address contained by the InetAddress object
8, you can use the static method of the InetAddress classgetLocalHost()Get a InetAddress Object
9. Network traffic uses an IP address to identify a computer on the Internet, using a port number to identify processes (programs) on the server.
10. When two programs need to communicate, they can create socket objects and link them together by using the socket class
11, socket is constructed by socket (String host, int port), host is the IP address of the server, port is a port number, IOException exception may occur.
12, when the socket object Clientsocket is established, Clientsocket can use the methodgetInputStream()To get an input stream, you can use the methodgetOutputStream()Gets an output stream.
13, ServerSocket is constructed by serversocket (int port), port is a port number. The port must be the same as the port number that the customer is calling.
14. ServerSocket Callaccept()method returns a socket object that is connected to the client socket object, SC.
15. The Accept method blocks the execution of the thread until it receives a call from the user.
16. ServerSocket object can call the setsotimeout (int timeout) method to set the time-out value (MS), timeout is a positive value, when the ServerSocket object calls the Accept method blocking time exceeds timeout, Trigger sockettimeoutexception.
17, you can use the socket class construction method without parameters socket () to create a socket object, the object needs to callpublic void connect(SocketAddress endpoint) throws IOException
18, in order to use the Connect method, you can create an object using the SocketAddress subclass Inetsocketaddress, Inetsocketaddress is constructed by:public InetSocketAddress(InetAddress addr, int port)
19, the basic mode based on UDP communication is:

    • Package the data, called a packet, and then send the packet to the destination;
    • Receive the sent packets, and then view the contents of the packet.
      20, using the Datagrampacket class to package data, that is, using the Datagrampacket class to create an object, called a packet.
      21. Create a packet to be sent with the following two construction methods of Datagrampacket:
      DatagramPacket(byte data[],int length,InetAddtress address,int port)
      DatagramPack(byte data[],int offset,int length,InetAddtress address,int port)
      22. Receive the packet:
      (1) Create an object with another construction method of Datagramsocket DatagramSocket(int port) , where the parameters must be the same as the port number of the packet to be received.
      (2) Object Mail_in uses the method to accept the packet receive(DatagramPacket pack) .
      (3) Another construction method using the Datagrampack class: DatagramPack(byte data[],int length) Create a packet to receive the packet
      Code Hosting

20165323 Java programming Nineth Week of study summary

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.