socket地址的通配符地址、环回地址、localhost

今天在写ServerSocket的时候,遇到了socket地址的通配符地址、环回地址、localhost。

package com.thb;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;

public class ServerSocketMain {

	public static void main(String[] args) {
		ServerSocket server = null;
		try {
			server = new ServerSocket(22335);
			InetAddress address = server.getInetAddress();
			System.out.println("ServerSocket绑定的地址:"+ address);
			System.out.println("是否通配符地址:" + address.isAnyLocalAddress());			
			System.out.println("是否环回地址:" + address.isLoopbackAddress());
			System.out.println();
			System.out.println("环回地址:" + InetAddress.getLoopbackAddress());
			System.out.println("localhost:" + InetAddress.getLocalHost());			

		} catch (IOException e) {			
			
		} finally {
			try {
				server.close();
			} catch (IOException e) {				
				
			}
		}

	}

}

执行输出:
socket地址的通配符地址、环回地址、localhost_第1张图片

你可能感兴趣的:(tcp/ip,java,网络协议)