Usually this error means that the V6 address for the remote machine is not actually bound to this port. For example, if you can talk to the web server via IPV4 on port 80, this does not mean that it actually binds the local V6 address to the port. You can still ping the machine, but ping does not really tell you if the port is connected.
A quick test to prove the correct use of your socket:
On a Windows Eclipse Machine
- At the command prompt, type netstat -p TCPv6 -a
- Select one of the localhost "::" entries. In this example, my machine returns [::]: 135 as one of the current ports associated with V6.
Try connecting to Eclipse:
public static void main(String[] args) { try { InetAddress address = InetAddress.getByName("::"); Socket socket = new Socket(address, 135); // Should of connected with no exception thrown since we know this port was listening in netstat } catch (Throwable t) { t.printStackTrace(); } }
I know that the above will not help you with your current code, but it is more aimed at excluding the possibility that IPV6 address and port # are not connected, and Socket connection exception is valid.
Another test I did was capture an Inet6 address for my Linux machine and an insured SSH listening on that port. Then I used the same code from my eclipse of Windows and made a socket against my Linux Inet6 address and port 22. This also worked fine. My local tomcat failed because it was not configured to listen to Inet6.
source share