Package org.jboss.netty.handler.codec.socks

Examples of org.jboss.netty.handler.codec.socks.SocksCmdRequest


    this.cf = cf;
  }

  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    final SocksCmdRequest socksCmdRequest = (SocksCmdRequest) e.getMessage();
    final Channel inboundChannel = e.getChannel();
    inboundChannel.setReadable(false);

    // Start the connection attempt.
    final ClientBootstrap cb = new ClientBootstrap(cf);
    cb.setOption("keepAlive", true);
    cb.setOption("tcpNoDelay", true);
    cb.setPipelineFactory(new ChannelPipelineFactory() {
      @Override
      public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = Channels.pipeline();
        // 外部server数据转发到client
        pipeline.addLast("outboundChannel", new OutboundHandler(inboundChannel, "out"));
        return pipeline;
      }
    });

    ChannelFuture f = cb.connect(new InetSocketAddress(socksCmdRequest.getHost(), socksCmdRequest.getPort()));

    outboundChannel = f.getChannel();
    ctx.getPipeline().remove(getName());
    f.addListener(new ChannelFutureListener() {
      public void operationComplete(ChannelFuture future) throws Exception {
        if (future.isSuccess()) {
          // client数据转发到外部server
          inboundChannel.getPipeline().addLast("inboundChannel", new OutboundHandler(outboundChannel, "in"));
          inboundChannel.write(new SocksCmdResponse(SocksMessage.CmdStatus.SUCCESS, socksCmdRequest
              .getAddressType()));
          inboundChannel.setReadable(true);
        } else {
          inboundChannel.write(new SocksCmdResponse(SocksMessage.CmdStatus.FAILURE, socksCmdRequest
              .getAddressType()));
          inboundChannel.close();
        }
      }
    });
View Full Code Here

TOP

Related Classes of org.jboss.netty.handler.codec.socks.SocksCmdRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.