Class SocketAddress


  • public class SocketAddress
    extends Object
    This class implements an IP Socket Address (IP address + port number)
    • Field Detail

      • hostname

        private String hostname
        The hostname of the Socket Address
      • addr

        private InetAddress addr
        The IP address of the Socket Address
      • port

        private int port
        The port number of the Socket Address
    • Constructor Detail

      • SocketAddress

        public SocketAddress​(String hostname,
                             int port)
        Creates a socket address from a hostname and a port number.
        Parameters:
        hostname - the Host name
        port - The port number
    • Method Detail

      • resetAddr

        public InetAddress resetAddr()
        Resolves the IP address for this hostname, don't use an eventually caching address.
        Returns:
        the resolved IP address.
      • getPort

        public int getPort()
        Gets the port number.
        Returns:
        the port number.
      • getHostname

        public String getHostname()
        Gets the hostname.
        Returns:
        the hostname part of the address.
      • getAddress

        public InetAddress getAddress()
        Gets the InetAddress.
        Returns:
        the InetAdress or null if it is unresolved.
      • equals

        public boolean equals​(Object obj)
        Compares this object against the specified object.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare against.
        Returns:
        true if the objects are the same; false otherwise.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toString

        public String toString()
        Constructs a string representation of this InetSocketAddress.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this object.