java InetSocketAddress 与 InetAddress

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14648699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 16:57:42  来源:igfitidea点击:

InetSocketAddress vs InetAddress

javanetwork-programming

提问by Rajat

Can anyone please explain me is there is any difference between InetAddressand InetSocketAddressclasses in java, and if there is a difference, please explain the same. I google-ed it up but I couldn't find anything explanatory.

任何人都可以解释一下java中的InetAddressInetSocketAddress类之间有什么区别,如果有区别,请解释相同。我用谷歌搜索了它,但找不到任何解释。

回答by Robin Chander

InetAddress

网络地址

An instance of an InetAddress consists of an IP address and possibly its corresponding host name

InetAddress 的实例由 IP 地址和可能的对应主机名组成

InetSocketAddress

接口地址

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

这个类实现了一个IP Socket地址(IP地址+端口号),也可以是一对(主机名+端口号),在这种情况下会尝试解析主机名

回答by mike

They represent different OSI layers:

它们代表不同的OSI 层