博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java InetSocketAddress 类说明
阅读量:5907 次
发布时间:2019-06-19

本文共 2226 字,大约阅读时间需要 7 分钟。

hot3.png

一、InetSocketAddress

final Socket socket = new Socket();//使用不可变对象,用于连接SocketAddress address = new InetSocketAddress("www.fortify.net", 443);try {    socket.connect(address);} catch (IOException e) {    // TODO Auto-generated catch block    e.printStackTrace();}// 连接远程主机Thread reader = new Thread() {    @Override    public void run() {        try {            byte[] buffer = new byte[512];            InputStream stream = socket.getInputStream();            socket.getInputStream().read(buffer);        } catch (Exception ex) {         }    }};reader.start();

JDK API Class InetSocketAddress

    • java.net.InetSocketAddress //是Socketaddress 的子类

    • public class InetSocketAddressextends SocketAddress

This class implements an IP Socket Address (IP address + port number) It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname.

这个类 inetAddress是Java对IP地址的封装,代表互联网协议(IP)地址;

InetAddress对象的获取只能通过静态方法,比如根据主机名获取主机的ip地址封装对象:

If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy.

It provides an immutable object used by sockets for binding, connecting, or as returned values.

The wildcard is a special local IP address. It usually means "any" and can only be used for bind operations.

  • Since:

  • 1.4

  • See Also:

  • , , 

  • All Implemented Interfaces:

二、InetAddress

InetAddress是Java对IP地址的封装,代表互联网协议(IP)地址;

InetAddress对象的获取只能通过静态方法,比如根据主机名获取主机的ip地址封装对象;

InetAddress add=InetAddress.getByName("BOPZKQZ9SSY5ECY");

JDK API Class InetSocketAddress

Class InetAddress

    • java.net.InetAddress

    • public class InetAddressextends Objectimplements Serializable

This class represents an Internet Protocol (IP) address.

  • An IP address is either a 32-bit or 128-bit unsigned number used by IP, a lower-level protocol on which protocols like UDP and TCP are built. The IP address architecture is defined by , , , and . An instance of an InetAddress consists of an IP address and possibly its corresponding host name (depending on whether it is constructed with a host name or whether it has already done reverse host name resolution).

  • Direct Known Subclasses:

  • All Implemented Interfaces:

转载于:https://my.oschina.net/u/2308739/blog/416222

你可能感兴趣的文章
Mysql二种安装
查看>>
语文论文范文:影视资源融入高中语文教学的探究
查看>>
Redis
查看>>
再谈CVE-2017-7047 Triple_Fetch和iOS 10.3.2沙盒逃逸
查看>>
克拉克拉(KilaKila):大规模实时计算平台架构实战
查看>>
在Fedora 30系统中安装深度DDE桌面
查看>>
聊聊 Redis 使用场景
查看>>
Java数据结构和算法(十一)——红黑树
查看>>
如何在Adobe Illustrator中创建抽象图标集
查看>>
视频下载离线工具—“Softorino YouTube Converter”
查看>>
oracle sql monitor
查看>>
我的友情链接
查看>>
MySQL日期数据类型、时间类型使用总结
查看>>
我的友情链接
查看>>
CentOS-5.6-x86_64 配置SSH无密码登陆
查看>>
EMC VNX点检向导
查看>>
几种任务调度的 Java 实现方法与比较
查看>>
module 'markdown' has no attribute 'version'
查看>>
nginx封禁IP--HttpLimitReqModule
查看>>
一个计算机专业大学生的一期学习总结
查看>>