Java InetSocketAddress 类说明
2015-05-18 00:00
239 查看
摘要: 学会查JDK api 感谢 OSChina 提供的 在线 查阅方法 http://tool.oschina.net/apidocs/apidoc?api=jdk_7u4
java.net.SocketAddress
java.net.InetSocketAddress //是Socketaddress 的子类
This class implements an IP Socket Address (IP address + port number) It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname.
这个类 inetAddress是Java对IP地址的封装,代表互联网协议(IP)地址;
InetAddress对象的获取只能通过静态方法,比如根据主机名获取主机的ip地址封装对象:
If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy.
It provides an immutable object used by sockets for binding, connecting, or as returned values.
The wildcard is a special local IP address. It usually means "any" and can only be used for
Since:
1.4
See Also:
All Implemented Interfaces:
Serializable
InetAddress对象的获取只能通过静态方法,比如根据主机名获取主机的ip地址封装对象;
Class InetAddress
java.lang.Object
java.net.InetAddress
This class represents an Internet Protocol (IP) address.
An IP address is either a 32-bit or 128-bit unsigned number used by IP, a lower-level protocol on which protocols like UDP and TCP are built. The IP address architecture is defined by RFC 790: Assigned Numbers, RFC 1918: Address Allocation for Private Internets, RFC 2365: Administratively Scoped IP Multicast, and RFC 2373: IP Version 6 Addressing Architecture. An instance of an InetAddress consists of an IP address and possibly its corresponding host name (depending on whether it is constructed with a host name or whether it has already done reverse host name resolution).
Direct Known Subclasses:
Inet4Address, Inet6Address
All Implemented Interfaces:
Serializable
一、InetSocketAddress
final Socket socket = new Socket();//使用不可变对象,用于连接 SocketAddress address = new InetSocketAddress("www.fortify.net", 443); try { socket.connect(address); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }// 连接远程主机 Thread reader = new Thread() { @Override public void run() { try { byte[] buffer = new byte[512]; InputStream stream = socket.getInputStream(); socket.getInputStream().read(buffer); } catch (Exception ex) { } } }; reader.start();
JDK API Class InetSocketAddress
java.lang.Objectjava.net.SocketAddress
java.net.InetSocketAddress //是Socketaddress 的子类
public class InetSocketAddressextends SocketAddress
This class implements an IP Socket Address (IP address + port number) It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname.
这个类 inetAddress是Java对IP地址的封装,代表互联网协议(IP)地址;
InetAddress对象的获取只能通过静态方法,比如根据主机名获取主机的ip地址封装对象:
If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy.
It provides an immutable object used by sockets for binding, connecting, or as returned values.
The wildcard is a special local IP address. It usually means "any" and can only be used for
bindoperations.
Since:
1.4
See Also:
Socket,
ServerSocket, Serialized Form
All Implemented Interfaces:
Serializable
二、InetAddress
InetAddress是Java对IP地址的封装,代表互联网协议(IP)地址;InetAddress对象的获取只能通过静态方法,比如根据主机名获取主机的ip地址封装对象;
InetAddress add=InetAddress.getByName("BOPZKQZ9SSY5ECY");
JDK API Class InetSocketAddress
Class InetAddress
java.lang.Objectjava.net.InetAddress
public class InetAddressextends Objectimplements Serializable
This class represents an Internet Protocol (IP) address.
An IP address is either a 32-bit or 128-bit unsigned number used by IP, a lower-level protocol on which protocols like UDP and TCP are built. The IP address architecture is defined by RFC 790: Assigned Numbers, RFC 1918: Address Allocation for Private Internets, RFC 2365: Administratively Scoped IP Multicast, and RFC 2373: IP Version 6 Addressing Architecture. An instance of an InetAddress consists of an IP address and possibly its corresponding host name (depending on whether it is constructed with a host name or whether it has already done reverse host name resolution).
Direct Known Subclasses:
Inet4Address, Inet6Address
All Implemented Interfaces:
Serializable
相关文章推荐
- Java笔记(9)-网络编程、URL、InetAddress、套接字、Socket、ServerSocket、多线程、UDP、广播数据包、远程调用
- Java.UDP-TCP-DatagramSocket-DatagramPacket-InetAddress-ServerSocket-Socket
- Java.UDP-TCP-DatagramSocket-DatagramPacket-InetAddress-ServerSocket-Socket
- java点滴之InetAddress类和InetSocketAddress的使用
- java之InetAddress类和InetSocketAddress的使用
- Java中InetAddress和InetSocketAddress的区别
- 黑马程序员--Java网络编程(InetAddress、DatagramSocket、DatagramPacket)
- Java学习之网络编程--InetAddress,InetSocketAddress
- Java学习-InetAddress和InetSocketAddress
- java点滴之InetAddress类和InetSocketAddress的使用
- 网络编程_InetAddress_InetSocketAddress_URL_爬虫原理JAVA185-186
- java:网络编程(InetAddress,InetSocketAddress,URL,TCP(Socket与SeverSocket),TCP与UDP的区别)
- java点滴之InetAddress类和InetSocketAddress的使用
- 基于TCP/UDP的Socket网络通信系列之Java中的InetAddress的应用(二)
- SocketAddress与 InetSocketAddress
- java网络编程之InetAddress
- java二十三节-InetAddress与URL
- elasticsearch出现java.net.Inet6AddressImpl.lookupAllHostAddr(Ljava/lang/String;)[Ljava/net/InetAddress
- [Java] InetAddress 获得ip地址和主机名
- org.apache.harmony.tests.java.net.InetAddressTest#test_isReachableLjava_net_NetworkInterfaceII 分析