20165232 The ninth week study summary

The ninth week of learning summary

learning material content

Chapter 13 Summary

  • URL class

    URL类是java.net包中的一个重要的类,URL的实例封装着一个统一资源定位符(Uniform Resource Locator),使用URL创建对象的应用程序称作客户端程序。
    一个URL对象通常包含最基本的三部分信息:协议、地址、资源。
  • The constructor of the URL object:

public URL (String spec) throws MalformedURLException
public URL (String protocol, String host, String file) throws MalformedURLException
  • InetAddress class
java.net 包中的 InetAddress 类对象含有一个 Internet 主机地址的域名和 IP 地址。
使用 InetAddress 类的静态方法 getByName(String s) 将一个域名或 IP 地址传递给该方法的参数 S,获得一个 InetAddress 对象,该对象格式为 <域名>/
获取域名和 IP 地址
  • socket
  1. Network communications use IP addresses to identify computers on the Internet and port numbers to identify processes (programs) on servers.
  2. The construction method of Socket is Socket(String host, int port), host is the IP address of the server, port is a port number, and an IOException may occur.
  3. The constructor of ServerSocket is ServerSocket(int port), and port is a port number.
  4. The ServerSocket.accept() method returns a Socket object connected to the client's Socket object.
  5. The output stream obtained by getOutputStream() will point to the input stream of the client Socket object, and the input stream obtained by getInputStream() will point to the input stream of the client Socket object.
  6. The ServerSocket object can call the setSoTimeout(int timeout) method to set the timeout value (ms), and the accept blocking time is too long to trigger a SocketTimeoutException.
  • Use multithreading technology

Use the constructor Socket() of the Socket class without parameters to create a socket object, which needs to be called

public void connect(SocketAddress endpoint) throws IOException
  • send packets
  1. Use the DatagramPacket class to pack the data, that is, use the DatagramPacket class to create an object called a data packet.
    Use the following two constructors of DatagramPacket to create packets to be sent:
DatagramPacket(byte data[],int length,InetAddtress address,int port)
DatagramPack(byte data[],int offset,int length,InetAddtress address,int port)
  1. Use the DatagramSocket class's parameterless constructor: DatagramSocket() to create an object that is responsible for sending packets.

code hosting

image

learning progress bar

Lines of code (added/accumulated) Blog volume (new/cumulative) Study time (added/accumulated) important growth
Target 5000 lines 20 articles 400 hours
the first week 13/13 1/1 17/17
the second week 408/408 2/2 18/18
The third week 962/962 1/1 22/22
the fourth week 1350/1350 1/1 19/19
fifth week 1361/1361 1/1 20/20
Week 6 2515/2515 1/1 20/20
Week 7 583/583 1/1 20/20
eighth week 973/973 1/1 19/20
ninth week 591/591 2/2 19/19

Guess you like

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