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. I google-ed it up but I couldn't find anything explanatory.
public InetSocketAddress(int port) Creates a socket address where the IP address is the wildcard address and the port number a specified value. A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.
InetSocketAddress(String hostname, int port) : Creates a socketaddress object and binds it to specified port and host. Resolution of hostname is performed to find the IP address and that is used for binding purpose, not the host name. If the resolution returns null, the address will be flagged as unresolved.
Class SocketAddress As an abstract class, it is meant to be subclassed with a specific, protocol dependent, implementation. It provides an immutable object used by sockets for binding, connecting, or as returned values.
The InetAddress class doesn't have public constructors, so you create a new instance by using one of its factory methods: getByName(String host): creates an InetAddress object based on the provided hostname.
InetSocketAddress. public InetSocketAddress (int port) Creates a socket address where the IP address is the wildcard address and the port number a specified value. A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation. Parameters:
The two are equal if they represent the same inetaddress and port number, or hostname and port number in case of unresolved address. 9. hashcode () : Returns the hashcode for this InetSocketAddress object.
Two instances of InetSocketAddress represent the same address if both the InetAddresses (or hostnames if it is unresolved) and port numbers are equal. If both addresses are unresolved, then the hostname & the port number are compared.
The result is true if and only if the argument is not null and it represents the same address as this object. Two instances of InetSocketAddress represent the same address if both the InetAddresses (or hostnames if it is unresolved) and port numbers are equal.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With