[英]InetSocketAddress vs InetAddress
Can anyone please explain me is there is any difference between InetAddress
and InetSocketAddress
classes in java, and if there is a difference, please explain the same. 任何人都可以解释一下,我在java中的
InetAddress
和InetSocketAddress
类之间有什么区别,如果有区别,请解释一下。 I google-ed it up but I couldn't find anything explanatory. 我谷歌了,但我找不到任何解释。
An instance of an InetAddress consists of an IP address and possibly its corresponding host name InetAddress的实例由IP地址和可能的相应主机名组成
InetSocketAddress 如果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套接字地址(IP地址+端口号)它也可以是一对(主机名+端口号),在这种情况下,将尝试解析主机名
They represent different OSI layers : 它们代表不同的OSI层 :
An InetAddress
corresponds to the Network Layer (Layer 3) and is basically an IP address. InetAddress
对应于网络层(第3层) ,基本上是IP地址。
A InetSocketAddress
corresponds to the Transport Layer (Layer 4) and consists of an IP address and a port number. InetSocketAddress
对应于传输层(第4层) ,由IP地址和端口号组成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.