org.licas.server.model

## Class ServerAddress

- java.lang.Object
- - org.licas.server.model.ServerAddress

-     public class ServerAddress
      extends java.lang.Object

  This stores and processes URI or IP addresses for a server object.
  Author:
    Kieran Greer

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ServerAddress(java.lang.String theIpAddress, int thePort, boolean asHttps)` Create a new instance of ServerAddress.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `checkAddress(java.lang.String host, int port)` Return true if the IP address and port compares to the address the server is running on.
    `static java.net.InetAddress` | `getLocalHost4Address()` This code is third-party from the Internet.
    `java.lang.String` | `getUrlAddress()` Return the URL address of the static HTTP server.
    `static java.util.ArrayList<java.lang.String>` | `ips(java.lang.String hostAddress)` Retrieve a list of alternative ip addresses (127.0.0.1) for the local computer.
    `boolean` | `isLocalIPAddress(java.lang.String theIPAddress)` Return true if the IP address represents a local server.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ServerAddress

          public ServerAddress(java.lang.String theIpAddress,
                               int thePort,
                               boolean asHttps)
                        throws java.lang.Exception

      Create a new instance of ServerAddress.
      Parameters:
        `theIpAddress` - the IP address to start the server on.
        `thePort` - the port to run on.
        `asHttps` - true if add as an https address and not an http address.
      Throws:
        `java.lang.Exception` - any error.

  - ### Method Detail

    - #### isLocalIPAddress

          public boolean isLocalIPAddress(java.lang.String theIPAddress)
                                   throws java.lang.Exception

      Return true if the IP address represents a local server.
      Parameters:
        `theIPAddress` - the IP address to compare. Note ip not url address.
      Returns:
        true if a local urlAddress.
      Throws:
        `java.lang.Exception` - any error.

    - #### checkAddress

          public boolean checkAddress(java.lang.String host,
                                      int port)
                               throws java.lang.Exception

      Return true if the IP address and port compares to the address the server is running on.
      Parameters:
        `host` - the host address. Can include 'localhost' or '127.0.0.1'.
        `port` - the port.
      Returns:
        true if the whole address agrees with the server address.
      Throws:
        `java.lang.Exception` - any error.

    - #### getUrlAddress

          public java.lang.String getUrlAddress()

      Return the URL address of the static HTTP server.
      Returns:
        the value of urlAddress.

    - #### getLocalHost4Address

          public static java.net.InetAddress getLocalHost4Address()
                                                           throws java.net.UnknownHostException

      This code is third-party from the Internet. Returns an `InetAddress` object encapsulating what is most likely the machine's LAN IP address. This has been changed to return an ipV4 address only. For any other type you should include the address in startup script.

      This method is intended for use as a replacement of JDK method `InetAddress.getLocalHost`, because that method is ambiguous on Linux systems. Linux systems enumerate the loopback network interface the same way as regular LAN network interfaces, but the JDK `InetAddress.getLocalHost` method does not specify the algorithm used to select the address returned under such circumstances, and will often return the loopback address, which is not valid for network communication. Details here.

      This method will scan all IP addresses on all network interfaces on the host machine to determine the IP address most likely to be the machine's LAN address. If the machine has multiple IP addresses, this method will prefer a site-local IP address (e.g. 192.168.x.x or 10.10.x.x, usually IPv4) if the machine has one (and will return the first site-local address if the machine has more than one), but if the machine does not hold a site-local address, this method will return simply the first non-loopback address found (IPv4 or IPv6).

      If this method cannot find a non-loopback address using this selection algorithm, it will fall back to calling and returning the result of JDK method `InetAddress.getLocalHost`.

      Returns:
        the first suitable match for a local host address (127.0.0.1).
      Throws:
        `java.net.UnknownHostException` - If the LAN address of the machine cannot be found.

    - #### ips

          public static java.util.ArrayList<java.lang.String> ips(java.lang.String hostAddress)
                                                           throws java.net.SocketException

      Retrieve a list of alternative ip addresses (127.0.0.1) for the local computer.
      Parameters:
        `hostAddress` - the current ip adress that the host is running on. Can be null.
      Returns:
        a list of alternative addresses for this computer/server.
      Throws:
        `java.net.SocketException` - network interface exception.