Java 7, Cisco AnyConnect, and SocketExceptions

This post is probably irrelevant to most readers, but I’m putting it online in the hope it saves someone hours of hair-pulling…

I’ve been holding off upgrading to Java 7 as every time I tried, I’d run into annoying issues preventing me from working. In particular, I was running into the issues discussed here. I thought I’d try again today with Java 7u1, but unfortunately immediately had the same issue. As in the previous link, my situation is that I need to use Cisco AnyConnect VPN client to connect to VPNs, and when I was attempting to pull down a remote file, I was getting the following exception:

ERROR:java.net.SocketException: Permission denied: connect
java.net.SocketException: Permission denied: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:316)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:177)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:164)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:154)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:390)
at java.net.Socket.connect(Socket.java:578)
at java.net.Socket.connect(Socket.java:527)
at java.net.Socket.(Socket.java:424)
at java.net.Socket.(Socket.java:279)

After spending many hours working through suggestions made on Google, I finally discovered the fix. It turns out that by disabling IPv6 in the VPN properties in Windows, the issue goes away. Here is the screenshot of how my properties dialog looks in Windows after making the change:

I hope this helps!

5 thoughts on “Java 7, Cisco AnyConnect, and SocketExceptions”

    1. My understanding (as per the discussion here) is that it is a change in behavior in Java 7, and a bug in AnyConnect that it doesn’t work well against IPv6. Of course, I’m not sure what the real issues are – just that this change above resolved the issue for me.

  1. I have the same issue under win 7 x64 with jdk1.6.29. I have tried disabling ipv6 with no luck. Anyone else ever have this issue? I can run the same code with win xp w/ anyconnect and no issues.

    Caused by: java.net.SocketException: Permission denied: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)

  2. Thanks a lot for the hint! I’ve run into this problem before without knowing its source. Didn’t really try to get to the bottom of it since I’m only rarely using VPN.

    Another possibility is to force-disable IPv6 in Java by setting the system property from the command line, like so:
    -Djava.net.preferIPv4Stack=true
    but in my case your method is much less cumbersome.

    Regards

Leave a Reply