201711671224 "Java Programming" Chapter 13 learning summary

Learning content summary

The URL class java.net package is an important class instance of a package with a URL Uniform Resource Locator (Uniform Resource Locator), using the application called URL creates client object.

A URL object usually contains three basic pieces of information: the protocol, address, resources.

URL class usually create a URL object using the constructor as follows:

public URL(String spec) throws MalformedURLException 

Get the address of the host on the Internet

Use the static method getByName InetAddress class (String s);

The client program uses the Socket class object is responsible for establishing a socket connection to the server.

Establish a connection to the server socket object:

try{ Socket mysocket=new Socket(“http://192.168.0.78”,1880);}

catch(IOException e){}

The method associated with mysocket

the getInputStream () to obtain an input stream

the getOutputStream () to obtain an output stream

With the getInputStream () obtained in the input stream to another data stream DataInputStream

With the getOutputStream () to get the output stream to another data stream DataOutputStream

1. DatagramPacket class data package, i.e., to create a class object with the DatagramPacket, called packets. Creating a data packet to be transmitted by the following two methods DatagramPacket configured to:

DatagramPacket(byte data[],int length,InetAddtress address,int port)

DatagramPack(byte data[],int offset,int length,InetAddtress address,int port)

Constructor with no arguments 2. Use of DatagramSocket: DatagramSocket () creates an object that is responsible for transmitting data packets. E.g:

DatagramSocket mail_out=new DatagramSocket();

mail_out.send(data_pack);

  • Constructor 1
try {  URL url = new URL("http://www.google.com");
}
catch(MalformedURLException e) {
   System.out.println("Bad URL:"+url);
}
  • Constructor 2: public URL(String protocol,String host,String file) throws MalformedURLException InetAddressGet address category
  • Gets the InetAddress host address, using the static method getByName (String s)
  • Gets the local machine address, getLocalHost with the static method ()
  • Sockets
  • ServerSocket object server side socket
  • The use of multi-threading technology

  • Datagram
通过网络传输的数据的基本单元,包含一个报头(header)和数据本身,其中报头描述了数据的目的地以及和其它数据之间的关系。
  • java remote call

InetAddress class

  • Address said: domain name, IP address
  • Get on the Internet host address: static method getByName InterAddress class (String s), return an object containing the domain name and IP address of the host address.

  • public String getHostName () Gets the object contained in the domain name
  • getHostAddress () Gets an object that contains an IP address.
  • Address access to the machine: the static method InterAddress class getLocalHost (), returns the object containing the local machine names and IP addresses.

Broadcast Datagram:

  • Class D addresses are not used to the position that you represent, that you can not use a class D address on the network to find the computer.
  • 224.0.0.0 ~ 224.255.255.255 is reserved addresses, called class D address.
  • To receive a broadcast or a broadcast of the same host must be added to a class D address.

Code debugging and problem solving in the process

  • No

Other (perception, thinking, etc.)

no

Reference material

  • "Java Programming"

Guess you like

Origin blog.csdn.net/nemeziz/article/details/85042822