今天在写ServerSocket的时候,遇到了socket地址的通配符地址、环回地址。
package com.thb;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
public class ServerSocketMain {
public static void main(String[] args) {
try {
ServerSocket server = new ServerSocket(22335);
InetAddress local = server.getInetAddress();
System.out.println("ServerSocket绑定的地址:"+ server.getInetAddress());
System.out.println("是否通配符地址:" + local.isAnyLocalAddress());
System.out.println("是否环回地址:" + local.isLoopbackAddress());
System.out.println("环回地址:" + InetAddress.getLoopbackAddress());
} catch (IOException e) {
e.printStackTrace();
}
}
}
执行输出: