Java SOCKS 代理 [英] Java SOCKS proxy

查看:72
本文介绍了Java SOCKS 代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

socksProxyHost 属性是否需要 IP 地址?

Does the socksProxyHost property require an IP address?

System.setProperty("socksProxyHost", preferences.getProxyHost() );

像上面一样设置,如果我提供 127.0.0.1,我就会连接到我的本地主机上的代理.但是如果我提供本地主机,它不会连接它.我在局域网上没有其他机器可以使用这个.那么有谁知道它是否适用于主机名,或者我是否必须解析主机并传入 IP?

Setting it like above, if I provide 127.0.0.1, I get connected to the proxy on my localhost. But if I provide localhost, it does not connect it. I have no other machines on the LAN I can use to this. So does anyone know if it works with hosts names or do I have to resolve the host and pass in an IP?

推荐答案

系统属性只是一张哑图.当值发生变化时,不会通知观察者.只读取一次值并将其存储在 private static final 中是正常的,而不是每次需要时都查找该值.

System properties are just a dumb map. There are no observers to be notified when a value changes. It is normal to read a value just once and store it in a private static final, rather than looking the value up every time that it is needed.

可能是在加载应用程序时初始化了相关代码,因此已经读取了该值.快速浏览一下 API 文档,可以看到一种很有前景的调用方法来更改默认代理:ProxySelector.setDefault.

Probably the relevant code is initialised whilst loading your application, so the value has already been read. A quick look at the API docs shows a promising method to call to change the default proxy: ProxySelector.setDefault.

这篇关于Java SOCKS 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆