java 的 socket 依赖了 nameService. 引擎模式.
使得 socket tcp 层 具有了上层业务的能力 (应用层)
Socket socket=new Socket("www.baidu.com",8080);
其中解析后取到第一个ip.
public native InetAddress[] lookupAllHostAddr(String hostname) throws UnknownHostException;
at Inet6AddressImpl.lookupAllHostAddr();
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at java.net.InetAddress.getByName(InetAddress.java:1076) 对应的代码是return InetAddress.getAllByName(host)[0];
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:220)
at java.net.Socket.<init>(Socket.java:211)
at com..test.unmock.MainTest.main(MainTest.java:23)