简体   繁体   中英

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?

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 eg "-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.

您可以通过java.net.Proxy.编程方式进行操作java.net.Proxy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM