Java InetSocketAddress 類說明

1、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.Objecthtml

  • java.net.SocketAddressjava

    • 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

2、InetAddress

InetAddress是Java對IP地址的封裝,表明互聯網協議(IP)地址;

InetAddress對象的獲取只能經過靜態方法,好比根據主機名獲取主機的ip地址封裝對象;

InetAddress add=InetAddress.getByName("BOPZKQZ9SSY5ECY");

JDK API Class InetSocketAddress

Class InetAddress

相關文章
相關標籤/搜索