Test for both IPv4 and IPv6 support to determine if either 127.0.0.1 or [::1] are appropriate IP addresses to attempt to connect to. In an IPv6-only environment, 127.0.0.1 is not available.
Using localhost is problematic because we might not be able to get the same port on each IP flavor, and later try to connect to the wrong thing.
nit