Search code examples
javaproxysocks

How to connect to a SOCKS proxy in a java applet


I've made a Java applet that accesses a webpage. I need it to connect to a website via a SOCKS proxy I've already tried putting this code where my program initialises:

System.setProperty("socksProxyHost", "66.85.144.228");
System.setProperty("socksProxyPort", "1080");

But nothing seems to happen and it just uses my normal IP address?


Solution

  • Your properties might be being set too-late, after they have already been read by the relevant code when it initializes, but you are also probably hitting the security restrictions of a sandboxed applet. Is your applet signed, or is it running sandboxed?

    If this were a Java Application rather than an applet, you could test this by setting these on your JVM launch e.g. "-DsocksProxyHost=66.85.144.228 -DsocksProxyPort=1080".

    Since you are working with an applet, there are restrictions on what system properties you can set. You can set deployment parameters:

    <APPLET archive="my_applet.jar" code="MyApplet" width="300" height="300">
        <PARAM name="java_arguments" value="-DsocksProxyHost=66.85.144.228">
    </APPLET>
    

    ... however socksProxyHost is of course not in the list of trusted/secure properties, so your applet would need to be completely signed to be runnable.