前段时间写了个http代理程序(科学上网),有window跟android客户端,以及服务端,github:https://github.com/scientificCommunity/proxy-server
欢迎大家一起参与或者给出宝贵建议
下面结合核心代码大概总结一下原理
ServerBootstrap serverEndpoint = new ServerBootstrap();
EventLoopGroup eventExecutors = new NioEventLoopGroup();
try {
serverEndpoint.group(eventExecutors)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 200)
.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel sc) throws Exception {
sc.pipeline()