Android,错误套接字异常 (SOCKS)
我尝试通过 Android 客户端应用程序(Android OS 1.5 和 1.6)中的 SOCKS 服务器连接到服务器,代码片段如下:
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(Constants.SOCKS_PROXY_HOST, Constants.SOCKS_PROXY_PORT));
socket = new Socket(proxy);
InetSocketAddress dest = new InetSocketAddress(targetHost,targetPort);
socket.connect(dest);
但是它在最后一行给出了异常:
W/System.err( 507): java.net.SocketException: SOCKS connection failed: java.net.SocketException: Bad socket
W/System.err( 507): at org.apache.harmony.luni.net.PlainSocketImpl.socksConnect(PlainSocketImpl.java:389)
W/System.err( 507): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:224)
W/System.err( 507): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:521)
W/System.err( 507): at java.net.Socket.connect(Socket.java:1019)
W/System.err( 507): at java.net.Socket.connect(Socket.java:960)
任何人都可能知道我哪里做错了? 提前致谢。
I tried to connect to a server through a SOCKS server in an Android client app (Android OS 1.5 and 1.6) with below snippet code:
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(Constants.SOCKS_PROXY_HOST, Constants.SOCKS_PROXY_PORT));
socket = new Socket(proxy);
InetSocketAddress dest = new InetSocketAddress(targetHost,targetPort);
socket.connect(dest);
However it gave out an exception on the last line:
W/System.err( 507): java.net.SocketException: SOCKS connection failed: java.net.SocketException: Bad socket
W/System.err( 507): at org.apache.harmony.luni.net.PlainSocketImpl.socksConnect(PlainSocketImpl.java:389)
W/System.err( 507): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:224)
W/System.err( 507): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:521)
W/System.err( 507): at java.net.Socket.connect(Socket.java:1019)
W/System.err( 507): at java.net.Socket.connect(Socket.java:960)
Anyone might have an idea where did i do wrong?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
花了一段时间但终于找到了解决方案。似乎在多个 Android 设备上实现 java.net SOCKS 存在一些问题,即使两部手机具有相同的 Android 操作系统版本(在具有不同版本的几部手机上进行了测试)。无论如何,我必须在我的项目中使用另一个替代的袜子库:JSocks(http://jsocks.sourceforge.net/)
到目前为止,它在我测试过的几台设备上都表现得非常出色。
It took a while but finally found the solution. It seems that there's a bit problem with java.net SOCKS implementation on several Android devices, even when both phones have the same Android OS version (tested on several phones with different builds). Anyway, I have to use another alternative socks library on my project: JSocks (http://jsocks.sourceforge.net/)
And so far it works like a charm so far on several devices i've tested.