提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
创建一个InetSocketAddress对象
import java.net.InetSocketAddress; /** from n o w j a v a . c o m - 时 代 Java**/ public class Main { public static void main(String[] args) { InetSocketAddress addr1 = new InetSocketAddress("::1", 12889); printSocketAddress(addr1); InetSocketAddress addr2 = InetSocketAddress.createUnresolved("::1", 12881); printSocketAddress(addr2); } public static void printSocketAddress(InetSocketAddress sAddr) { System.out.println("Socket Address: " + sAddr.getAddress()); System.out.println("Socket Host Name: " + sAddr.getHostName()); System.out.println(