把分布在不同地理区域的计算机与专门的外部设备用通信线路互连成一个规模大、功能强的网络系统,从而使众多的计算机可以方便地互相传递信息、共享硬件、软件、数据信息等资源。
设备之间在网络中进行数据的传输,发送/接收数据。
域名:www.baidu.com --> DNS服务器解析 --> IP地址
www.sina.com
www.bbbb.com
建立连接: 三次握手
释放连接:四次挥手
public class Test01 {
//这是一个main方法,是程序的入口:
public static void main(String[] args) throws UnknownHostException {
//封装IP:
//InetAddress ia = new InetAddress();不能直接创建对象,因为InetAddress()被default修饰了。
InetAddress ia = InetAddress.getByName("192.168.199.217");
System.out.println(ia);
InetAddress ia2 = InetAddress.getByName("localhost");//localhost指代的是本机的ip地址
System.out.println(ia2);
InetAddress ia3 = InetAddress.getByName("127.0.0.1");//127.0.0.1指代的是本机的ip地址
System.out.println(ia3);
InetAddress ia4 = InetAddress.getByName("LAPTOP-LANSON");//封装计算机名
System.out.println(ia4);
InetAddress ia5 = InetAddress.getByName("www.baidu.com");//封装域名
System.out.println(ia5);
System.out.println(ia5.getHostName());//获取域名
System.out.println(ia5.getHostAddress());//获取ip地址
}
}
public class Test02 {
//这是一个main方法,是程序的入口:
public static void main(String[] args) {
InetSocketAddress isa = new InetSocketAddress("192.168.199.217",8080);
System.out.println(isa);
System.out.println(isa.getHostName());
System.out.println(isa.getPort());
InetAddress ia = isa.getAddress();
System.out.println(ia.getHostName());
System.out.println(ia.getHostAddress());
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。