My new laptop (Alienware m17x) throws a java.net.SocketException: Invalid argument: connect
when I run the following basic code:
Server.java:
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.
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
Also check if your IDE is using the JRE which you expect.
I had same issue:
java.sql.SQLException: JZ006: Caught IOException: java.net.SocketException: Invalid argument: create
When I checked my run configuration, my default JRE was pointing to 'Project Execution Environment 'JavaSE1.7' which was not I was expecting.
I changed it to option Alternate JRE and set the JAVA 8 as installed jre. which has solved my problem.
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.
Can you run other applications that connect to the network or localhost?
I have had a similar problem a while ago (only on Win7) and I fixed it by only going to Network connection-> Repain
. The problem came from the fact that my routing table was corrupted, the localhost
route disappeared from it and any application trying to connect to localhost
was crashing with the same error as yours.
Can you run route -print
in a command line and post the output?
EDIT: Sounds like your IP stack is corrupted, you might try this fix from MS
Please check if you installed JDK in the network location. if yes, please change the jdk location in the local drive disk and confirm there is no limit about permission