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();
java.lang.Objecthtml
java.net.InetSocketAddress //是Socketaddress 的子类api
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.socket
这个类 inetAddress是Java对IP地址的封装,表明互联网协议(IP)地址;ide
InetAddress对象的获取只能经过静态方法,好比根据主机名获取主机的ip地址封装对象:ui
If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy.spa
It provides an immutable object used by sockets for binding, connecting, or as returned values..net
The wildcard is a special local IP address. It usually means "any" and can only be used for bind
operations.code
Since:orm
1.4
See Also:
All Implemented Interfaces:
InetAddress是Java对IP地址的封装,表明互联网协议(IP)地址;
InetAddress对象的获取只能经过静态方法,好比根据主机名获取主机的ip地址封装对象;
InetAddress add=InetAddress.getByName("BOPZKQZ9SSY5ECY");
java.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:
All Implemented Interfaces: