Summary of learning contents of textbook
URL class
URL类是java.net包中的一个重要的类,URL的实例封装着一个统一资源定位符,使用URL创建对象的应用程序称作客户端程序。一个URL对象通常包含最基本的三部分信息:协议、地址、资源。构造方法: ```public URL(String spec) throws MalformedURLException
Public URL (String protocol, string host,string file) throws Malformedurlexception "
读取URL中的资源:URL对象调用```InputStream openStream()```
Inetadress class
地址的表示:域名和IP地址获取Internet上主机的地址:1.可以使用InetAddress类的静态方法getByName(String s);2.获得一个InetAddress对象,该对象含有主机地址的域名和IP地址,该对象用如下格式表示它包含的信息:
www.sina.com.cn/202.108.37.40
Get the address of the local machine
You can use the static method of the InetAddress class Getlocalhost () to obtain a InetAddress object that contains the domain name and IP address of the local machine.
Sockets
与mysocket相关的方法getInputStream()获得一个输入流getOutputStream()获得一个输出流用getInputStream()得到的输入流接到另一个DataInputStream数据流上用getOutputStream()得到的输出流接到另一个DataOutputStream数据流上ServerSocket对象与服务器端套接字:1.建立ServerSocket对象: ```try{ ServerSocket serverForClient =new ServerSocket(2010); }
2. Use the method accept () to connect the client socket and the server-side socket
```try{ Socket sc= serverForClient .accept(); } catch(IOException e){}```
3. The socket connection of the so-called "receiving" customer is the Accept () method that returns a socket object that is connected to the client socket object.
使用多线程技术为了防止堵塞线程,服务器端收到一个客户的套接字后,就应该启动一个专门为该客户服务的线程。
UDP datagram
基于UDP通信的基本模式是:1将数据打包,称为数据包(好比将信件装入信封一样),然后将数据包发往目的地。2.接受别人发来的数据包(好比接收信封一样),然后查看数据包中的内容。发送数据包1.用DatagramPacket的以下两个构造方法创建待发送的数据包:
DatagramPacket(byte data[],int length,InetAddtress address,int port) DatagramPack(byte data[],int offset,int length,InetAddtress address,int port)
2. Use the Datagramsocket class without parameters to construct a method: Datagramsocket () Creates an object that is responsible for sending the packet. For example:
DatagramSocket mail_out=new DatagramSocket(); mail_out.send(data_pack);
接收数据包1.用DatagramSocket的另一个构造方法DatagramSocket(int port) 创建一个对象,其中的参数必须和待接收的数据包的端口号相同。2.对象mail_in使用方法receive(DatagramPacket pack)接受数据包。3.用DatagramPack类的另外一个构造方法: DatagramPack(byte data[],int length)创建一个数据包,用于接收数据包
Broadcast Data Report
Java remote Invocation (RMI)
Code Hosting
Learning sentiment
This week I learned the Java-specific class for network programming, contacted the computer network class to learn the knowledge, the feeling harvest quite abundant.
Learning Progress
Completed more than 1200 lines of code, 16 blogs, 163 hours of study time
20165304 Java programming Nineth Week of study summary