*java.net.InetAddress: 此类表示互联网协议 (IP) 地址。
*如果一个类中没有字段,没有构造方法,那么该类某个成员方法是静态,而且返回值该类本身
*eg:
* InetAddress,Runtime(单例模式:饿汉式)
*静态功能:
* public static InetAddress getByName(String host)throws UnknownHostException
* 在给定主机名的情况下确定主机的 IP 地址
*
* TCP还是UDP:都称为网络编程--->Socket编程
* 特点:
* 1)两端(接收端/发送端):都需要Socket对象存在
* 2)必须指定ip地址以及特定的端口号
* 3)底层都是一种流的方式进行传输(比特流)
import java.io.IOException;
import java.net.InetAddress;
public class InetAddressDemo {
public static void main(String[] args) throws IOException {
// public static InetAddress getByName(String host)
InetAddress address=InetAddress.getByName("WL");
System.out.println(address);// WL/192.168.53.77
System.out.println("-----------------");
// public static InetAddress getByName(String host):可以指定主机名称或者IP地址字符串格式
// InetAddress address2=InetAddress.getByName("192.168.53.77");
// System.out.println(address2);
String ip=InetAddress.getByName("192.168.53.77").toString();
System.out.println(ip);
}
}
版权声明:本文为weixin_57219176原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。