java.net.SocketException: Invalid argument: connect

Does it work if you tell Java to use the IPv4 stack?

Use the following command line option when starting the server and client.

-Djava.net.preferIPv4Stack=true

See also here


I have an Alienware m17x R3 and I found that I had the exact same error with Java, though I encountered it with Minecraft. Installing older Java6u33 fixed the issue but I found that newer updates of Java7 still weren't working even after waiting several months. So I eventually went to the Dell website and downloaded the most recent network drivers for my Alienware laptop (since Alienware is now owned by Dell) and that fixed the problem right away.


Your machine seems to have an IPv6 configuration and is preferred by default in Java so try start your server and client with -Djava.net.preferIPv4Stack=true as JVM args:

  java -Djava.net.preferIPv4Stack=true Client.main

Also make sure you didn't deny the application network access when Windows' Firewall asked you for permission. If you did, you can change the settings in the control panel.


There is a Windows bug that affects not only Java applications and produces exactly this error in certain constellations where the JRE is located on a network share: https://bugs.openjdk.java.net/browse/JDK-8068568

Solution is either using a JRE installation on a local drive or granting the List Folder permission on all ancestor folders of the JRE exe.

In https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/3076a9cd-57a0-418d-8de1-07adc3b486bb it is suggested to add a DWORD value HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\FltMgr\UseTildeShortcut with content "1", which I didn't have a chance to try. I think I also remember reading a post on a Microsoft support forum which stated that this doesn't happen on network shares whose name is longer than 8 characters, but I can't find the post anymore.


I have figured out a way to make this a permanent change from here.

What you need to do is add a system variable named JAVA_TOOL_OPTIONS and set this to whatever you want to be passed to java as a commandline argument whenever it starts up, in yours and my case being

-Djava.net.preferIPv4Stack=true