Closed mariotaku closed 8 years ago
Seems it's a bug inside Android Socket implementation.
SOCKS working fine on Oracle JRE and OpenJDK JRE, and I looked into their code:
Socket.connect(SocketAddress endpoint, int timeout)
if (epoint.isUnresolved())
impl.connect(addr.getHostName(), port);
else
impl.connect(addr, port);
That's what I found in Android framework:
InetSocketAddress inetAddr = (InetSocketAddress) remoteAddr;
InetAddress addr;
if ((addr = inetAddr.getAddress()) == null) {
throw new UnknownHostException("Host is unresolved: " + inetAddr.getHostName());
}
int port = inetAddr.getPort();
checkDestination(addr, port);
synchronized (connectLock) {
try {
if (!isBound()) {
// socket already created at this point by earlier call or
// checkOpenAndCreate this caused us to lose socket
// options on create
// impl.create(true);
if (!usingSocks()) {
impl.bind(Inet6Address.ANY, 0);
}
isBound = true;
}
impl.connect(remoteAddr, timeout);
isConnected = true;
cacheLocalAddress();
} catch (IOException e) {
impl.close();
throw e;
}
}
Android only accept resolved InetSocketAddress
.
Could you report this issue upstream to AOSP? I’m not particularly eager to implement a SOCKS proxy inside of OkHttp. You might need to implement your own SocketFactory that implements SOCKS.
No action for us to take on this.
SOCKS proxy is completely broken on Android. When I set up SOCKS proxy in my app, all requests failed, when I wrote an instrumentation test, I found even create a default okhttp instance with a SOCKS proxy, it fails.
Here's the stack trace:
Sample code: