java网络编程读书笔记-Ch04 05
来源:互联网 发布:视频去水印软件 编辑:程序博客网 时间:2024/05/18 02:14
Internet Addresses
链接上网的设备被称为 nodes. Nodes that are computers are called hosts.
Domain Name System (DNS)
The InetAddress Class
java.net.InetAddress
The java.net.InetAddress class is Java’s high-level representation of an IP address, both IPv4 and IPv6. It is used by most of the other networking classes, including Socket, ServerSocket, URL, DatagramSocket, DatagramPacket, and more. Usually, it includes both a hostname and an IP address.
import java.net.*;public calss OReillByName{ public static void main(String[] args){ try{ InetAddress address = InetAddress.getByName("www.oreilly.com"); System.out.println(address); }catch(UnknownHostException ex){ System.out.println("Could not find www.oreilly.com") } }}
结果
JunrdeMacBook-Pro:src junr$ javac OReillyByName.java JunrdeMacBook-Pro:src junr$ java OReillyByNamewww.oreilly.com/23.42.171.129
Caching
These times can be controlled by the system properties networkaddress.cache.ttl and networkaddress.cache.negative.ttl.
Getter Methods
InetAddress
class 包含了四个getter方法。
public String getHostName()public String getCanonicalHostName()public byte[] getAddress()public String getHostAddress()
There are no corresponding setHostName() and setAddress() methods, which means that packages outside of java.net can’t change an InetAddress object’s fields behind its back. This makes InetAddress immutable and thus thread safe.
Ch05 URLs and URIs
A resource is a thing that is identified by a URI.
There is no specific syntax that applies to the scheme-specific parts of all URIs. However,
many have a hierarchical form, like this:
//authority/path?query
The authority part of the URI names the authority responsible for resolving the rest of the URI. For instance, the URI http://www.ietf.org/rfc/rfc3986.txt has the scheme http, the authority www.ietf.org, and the path /rfc/rfc3986.txt (initial slash included). This means the server at www.ietf.org is responsible for mapping the path /rfc/rfc3986.txt to a resource. This URI does not have a query part. The URI http://www.powells.com/cgi- bin/biblio?inkey=62-1565928709-0 has the scheme http, the authority www.po‐ wells.com, the path /cgi-bin/biblio, and the query inkey=62-1565928709-0. The URI urn:isbn:156592870 has the scheme urn but doesn’t follow the hierarchical //authority/ path?query form for scheme-specific parts.
Although most current examples of URIs use an Internet host as an authority, future schemes may not. However, if the authority is an Internet host, optional usernames and ports may also be provided to make the authority more specific. For example, the URI ftp://mp3:mp3@ci43198-a.ashvil1.nc.home.com:33/VanHalen-Jump.mp3 has the au‐ thority mp3:mp3@ci43198-a.ashvil1.nc.home.com:33. This authority has the username mp3, the password mp3, the host ci43198-a.ashvil1.nc.home.com, and the port 33. It has the scheme ftp and the path /VanHalen-Jump.mp3. (In most cases, including the pass‐ word in the URI is a big security hole unless, as here, you really do want everyone in the universe to know the password.)
If you don’t hexadecimally encode non-ASCII characters like this, but just include them directly, then instead of a URI you have an IRI (an Internationalized Resource Identi‐ fier). IRIs are easier to type and much easier to read, but a lot of software and protocols expect and support only ASCII URIs.
URLs
A URL is a URI that, as well as identifying a resource, provides a specific network location for the resource that a client can use to retrieve a representation of that resource.
In Java, it’s the difference between the java.net.URI class that only identifies resources and the java.net.URL class that can both identify and retrieve resources.
The syntax of a URL is:
protocol://userInfo@host:port/path?query#fragment
The host part of a URL is the name of the server that provides the resource you want. It can be a hostname such as www.oreilly.com or utopia.poly.edu or an IP address, such as 204.148.40.9 or 128.238.3.21.
The userInfo is optional login information for the server. If present, it contains a user‐ name and, rarely, a password.
The port number is also optional. It’s not necessary if the service is running on its default port (port 80 for HTTP servers).
Creating New URLs
public URL(String url) throws MalformedURLException public URL(String protocol, String hostname, String file)throws MalformedURLExceptionpublic URL(String protocol, String host, int port, String file)throws MalformedURLExceptionpublic URL(URL base, String relative) throws MalformedURLException
URI
URI voice = new URI("tel:+1-800-9988-9938");URIweb =newURI("http://www.xml.com/pub/a/2003/09/17/stax.html#id=_hbc"); URI book = new URI("urn:isbn:1-565-92870-9");
System Properties
The ProxySelector Class
public abstract List<Proxy> select(URI uri)
- java网络编程读书笔记-Ch04 05
- apue读书笔记-Ch04
- apue读书笔记-Ch04(2)
- java网络编程读书笔记-Ch02
- java网络编程读书笔记-Ch03
- java 网络 socket编程 Java核心技术读书笔记
- 《Java网络编程》读书笔记(一)
- 读书笔记-java网络编程-3线程-同步
- 读书笔记-java网络编程-7URLConnection-缓存
- Thinking in Java ---ch04笔记
- 《Java网络编程》读书笔记(二)socket编程
- 《Linux网络编程》读书笔记
- 读书笔记-java网络编程-3线程-java线程概述
- java线程编程读书笔记一(根据网络资料改编)
- think in java第十五章关于网络编程的读书笔记
- 读书笔记-java网络编程-3线程-从线程返回信息
- 读书笔记-java网络编程-3线程-线程调度
- 读书笔记-java网络编程-3线程-线程池和Executor
- mybatis执行任意sql,不配置resultMap,返回结果集
- Android 设计模式之 MVP(一)
- SMB文件共享
- Excel表格的项目demo
- Greenplum列存压缩表事务机制
- java网络编程读书笔记-Ch04 05
- 将字符串转换成json格式
- Android7.0共享文件权限
- Android开发,关于ZxUtils的使用(三)
- 欢迎使用CSDN-markdown编辑器
- 基于canvas实现计时器,请酷的哟,有源码分享
- ssh整合之不带hibernate配置文件的spring中的配置
- PowerDesigner写脚本的方式导入EXCEl表数据
- 详述 PO VO BO DTO DAO 和 POJO 的概念及区别