InetSocketAddress vs InetAddress

后端 未结 2 696
借酒劲吻你
借酒劲吻你 2021-01-04 04:46

Can anyone please explain me is there is any difference between InetAddress and InetSocketAddress classes in java, and if there is a difference, pl

相关标签:
2条回答
  • 2021-01-04 05:28

    They represent different OSI layers:

    • An InetAddress corresponds to the Network Layer (Layer 3) and is basically an IP address.

    • A InetSocketAddress corresponds to the Transport Layer (Layer 4) and consists of an IP address and a port number.

    0 讨论(0)
  • 2021-01-04 05:42

    InetAddress

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

    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

    0 讨论(0)
提交回复
热议问题