java dsocksproxy_How to config socks proxy in Java NIO

I'm developing a tool which includes forcing all network traffic of application to go across a socks proxy in Java. For old Socket API, I can just set system properties "-DsocksProxyHost=my-host -DsocksProxyPort=my-port", but it doesn't work with NIO.

I tried a solution:

I wrote an NIO SocketChannel, called "ProxySocketChannel" which extends SocketChannel. It contains socks connection and other socks proxy logic. But when I run it, I got an "IllegalSelectorException" in this line of code in "SelectorImpl.register":

if (!(ch instanceof SelChImpl))

throw new IllegalSelectorException();

sun.nio.ch.SelChImpl is package visible so I can't access it. I tried a tricky solution: I put my "ProxySocketChannel" in package "sun.nio.ch". The compilation passed, but I got an error when running:

java.lang.IllegalAccessError: class sun.nio.ch.ProxySocketChannel cannot access its superinterface sun.nio.ch.SelChImpl

I don't know why the class sun.nio.ch.ProxySocketChannel with package sun.nio.ch still can not access sun.nio.ch.SelChImpl. I think there is some protection for JDK built-in classes. Is there a way to access it?

My JDK Version is 1.6.0_65.

Otherwise, is there a way to setup socks proxy for NIO without change existing code?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值