S
S
sednka2014-02-05 14:19:04
Java
sednka, 2014-02-05 14:19:04

Why doesn't Java want to work with Socks 4 proxy?

Greetings!

Actually straight to the point. While working on the test program, the following problem arose: Java does not want to work with Socks 4 proxies, not at all. I explain the situation:

There is a code of the form

con = (HttpURLConnection) obj.openConnection(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("host", *port*));


        con.setConnectTimeout(Config.CONNECT_TIMEOUT);
        con.setReadTimeout(Config.READ_TIMEOUT);


        con.setRequestProperty("User-Agent", Config.USER_AGENT);

        con.setDoOutput(false);
        con.setDoInput(true);

        con.setRequestMethod("GET");


        con.connect();


Which, if we substitute socks 4 proxy here, gives:
java.net.SocketException: Malformed reply from SOCKS server


With socks 5 proxies everything is "ok".

Somewhere in 2 hours of active search, a similar topic was found:
bugs.java.com/view_bug.do?bug_id=6964547

And there is only one advice: set socksProxyVersion, which I do like this: It does not help. Furthermore! Some kind of terrible addiction begins: At the first start with socksProxyVersion installed, i.e. I added the following code to the beginning of the program: it accepted the socks 4 proxy and made money with it. BUT! At the same time, he suddenly refused. The mystic lies in the fact that if you change the code to: and then again to there is a chance that it will work. But then again, the last tests did not work! BUT! Here is a link:
System.setProperty("socksProxyVersion", "4");


System.setProperty("socksProxyVersion", "4");

System.setProperty("socksProxyVersion", "5");
System.setProperty("socksProxyVersion", "4");



System.setProperty("socksProxyVersion", "4");
        System.setProperty("socksProxyHost", "хост");
        System.setProperty("socksProxyPort", "порт");


It works with Sox 4/5 proxies, but I need different proxies for each stream, so this option is not suitable.

Could you clarify the situation? On one of the forums, they advised me to look for other implementations, but I have not found it yet.

Java:
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Proxies:
About 20 Socks 4 (all issued Malformed), the same number of Socks 5 (they did not issue Malformed at all).

Thank you in advance..

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sednka, 2014-02-05
@sednka

Alas, it is private SocksProxy(java.net.SocketAddress arg0, int arg1);

M
MisterParser, 2018-10-01
@MisterParser

There is no such problem in JDK11, it works with SOCKS4, but you need to set a system property.
You can also create SocksProxy, the method has become public:
public static SocksProxy create(SocketAddress addr, int version)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question