bindAddress property

InternetAddress bindAddress
getter/setter pair

Bind address for the server.

An InternetAddress for the server to bind to. This can be a real IP address or one of these special values: InternetAddress.loopbackIPv4, InternetAddress.loopbackIPv6, InternetAddress.anyIPv4 or InternetAddress.anyIPv6.

The default value is loopbackIPv4, which means it only listens on the IPv4 loopback address of 127.0.0.1. This option is usually used when the service is run behind a reverse proxy server (e.g. Apache or Nginx). The server can only be contacted over IPv4 from the same host. When configuring a reverse proxy server, sometimes it should be explicitly configured to use 127.0.0.1 instead of "localhost", since the later might cause it to try ::1 first (which will always fail) and then 127.0.0.1.

If deployed without a reverse proxy, this value needs to be change otherwise clients external to the machine will not be allowed to connect to the Web server.

If a non-loopback IPv6 InternetAddress is provided (and it has a IPv4 equivalent) it will listen on both the IPv6 and IPv4 address, unless v6Only is set to true. If it is set to true, then the IPv4 equivalent address will not be used and only the IPv6 address is used.

Important: the v6Only property does not apply to the loopback address InternetAddress.loopbackIPv6. So it is impossible to listen on both 127.0.0.1 and ::1 at the same time.

Implementation

InternetAddress bindAddress = InternetAddress.loopbackIPv4;