20

In an app which I have programmed, I have a java.net.SocketException on a specific computer:

java.net.SocketException: Address family not supported by protocol family: connect

This specific computer runs Windows 7 32 Bit and is connected to the internet through Local Area Connection (Ethernet). The app runs correctly on other computers, with Windows 7 and Windows 8, connected through Local Area Connection or through Wi-Fi, so I am actually not sure that the problem is programmatic. I have tried to check the protocols of the Local Area Connection, but I didn't see any problems. Can someone please help me understand what is the problem? Why is this exception thrown?

11
  • Try any network packet monitoring software like Wireshark
    – prasanth
    May 4, 2013 at 12:03
  • And what do I have to see there?
    – Or B
    May 4, 2013 at 12:05
  • You are trying to connect to some port,right?? Check if the TCP packets were received on that port and what was the response received
    – prasanth
    May 4, 2013 at 12:06
  • I am actually trying to work with HTTP, so it is port 80.
    – Or B
    May 4, 2013 at 12:12
  • You monitor the traffic on 80 after you run your code
    – prasanth
    May 4, 2013 at 12:14

6 Answers 6

40

Try to check whether the spy program called "RelevantKnowledge" is installed. Its uninstallation helped me to solve the problem.

3
  • It really could be the problem.
    – Or B
    Jan 27, 2014 at 16:51
  • 3
    I observed the same issue with another malware named "PremierOpinion". Jul 12, 2017 at 13:59
  • I don't know where this "RelevantKnowledge" come from but when I try this answer, it's working. Thanks Feb 15, 2021 at 16:32
26

For me Java option -Djava.net.preferIPv4Stack=true did the trick

20
  1. Open command prompt (windows start button, type cmd in search)
  2. Click top left of command prompt, click properties, enable quick edit mode
  3. Copy: setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true

  4. Right click on command prompt, should paste

  5. Hit enter. That easy!
1
  • I added it to Azure's 'App settings' in the portal and it worked!
    – lionello
    Mar 18, 2017 at 0:25
5

It may be a few things:

  • Anti-virus blocking the connection. If you have an anti-virus running on that computer, try disabling it for a test.
  • Java 7 trying to use IPv6 to connect: if you have Java 6 on the computers where it works and Java 7 where it fails, try disabling IPv6 in Java on the computer where it fails (instructions in this post)
4
  • It uses the same Anti-Virus as my computer does, and it runs the most updated version of Java 7. Please look at the comments to my question.
    – Or B
    May 4, 2013 at 13:34
  • See the bullet item about disabling IPv6 in Java 7. May 4, 2013 at 19:10
  • No, it's Java 7 in all of the computers.
    – Or B
    May 6, 2013 at 21:41
  • It may be worth trying disabling IPv6 on that computer for a test. It will ate least exclude it from the list of possible culprits. May 6, 2013 at 21:47
0

If you are using java 6, try to change to java 7. It works for me.

0

Thanks this helped me :

Anti-virus blocking the connection. If you have an anti-virus running on that computer, try disabling it for a test.

Open command prompt (windows start button, type cmd in search) Click top left of command prompt, click properties, enable quick edit mode Copy: setx _JAVA_OPTIONS -Djava.net.preferIPv4Stack=true Right click on command prompt, should paste Hit enter. That easy!

Not the answer you're looking for? Browse other questions tagged or ask your own question.