网络编程1
操作ip地址
核心类 InetAddress
相关方法 getByName,getAllByName,getLocalHost
操作socket地址
由ip地址(或主机名)与端口号组成
核心类 InetSocketAddress
相关方法
package java_20180213_api_net; import java.net.InetAddress; import java.net.InetSocketAddress; public class InetAddressDemo { public static void main(String[] args) throws Exception { // InetAddress ia=InetAddress.getLocalHost(); // System.out.println(ia.getHostName()); // System.out.println(ia.getHostAddress()); InetAddress[] ia1=InetAddress.getAllByName("DESKTOP-NMUHAH0"); for (InetAddress inetAddress : ia1) { System.out.println(inetAddress.getHostAddress()); } InetAddress ia2=InetAddress.getByName("edu.51cto.com"); System.out.println("edu: "+ia2.getHostAddress()); InetSocketAddress ia3=new InetSocketAddress(80); } }
网络编程2
uri,url,urn的概念
java中相关的类
java.net.URI
java.net.URL
java.net.URLEncoder
java.net.URLDecoder
网络编程3
通过java api访问url的内容
网络编程4
实现tcp服务器端socket
实现tcp客户端socket