Example usage for io.netty.handler.codec.socks SocksMessageEncoder SocksMessageEncoder

List of usage examples for io.netty.handler.codec.socks SocksMessageEncoder SocksMessageEncoder

Introduction

In this page you can find the example usage for io.netty.handler.codec.socks SocksMessageEncoder SocksMessageEncoder.

Prototype

SocksMessageEncoder

Source Link

Usage

From source file:cc.agentx.client.net.nio.XClient.java

License:Apache License

public void start() {
    Configuration config = Configuration.INSTANCE;
    InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    try {/*  w  w w.j ava2  s  . c om*/
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel socketChannel) throws Exception {
                        socketChannel.pipeline().addLast("logging", new LoggingHandler(LogLevel.DEBUG))
                                .addLast(new SocksInitRequestDecoder()).addLast(new SocksMessageEncoder())
                                .addLast(new Socks5Handler()).addLast(Status.TRAFFIC_HANDLER);
                    }
                });
        log.info("\tStartup {}-{}-client [{}{}]", Constants.APP_NAME, Constants.APP_VERSION, config.getMode(),
                config.getMode().equals("socks5") ? "" : ":" + config.getProtocol());
        ChannelFuture future = bootstrap.bind(config.getLocalHost(), config.getLocalPort()).sync();
        future.addListener(
                future1 -> log.info("\tListening at {}:{}...", config.getLocalHost(), config.getLocalPort()));
        future.channel().closeFuture().sync();
    } catch (Exception e) {
        log.error("\tSocket bind failure ({})", e.getMessage());
    } finally {
        log.info("\tShutting down");
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.github.sinsinpub.pero.frontend.SocksServerInitializer.java

License:Apache License

@Override
public void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline p = socketChannel.pipeline();
    p.addLast(new SocksInitRequestDecoder());
    p.addLast(new SocksMessageEncoder());
    p.addLast(socksServerHandler);// w w  w  .  j  a  va2s . c  o m
}

From source file:com.xx_dev.apn.socks.test.SocksClientInitializer.java

License:Apache License

@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
    ChannelPipeline p = socketChannel.pipeline();
    p.addLast("log", new LoggingHandler("BYTE_LOGGER", LogLevel.DEBUG));
    p.addLast(new SocksInitResponseDecoder());
    p.addLast(new SocksMessageEncoder());
    p.addLast(new SocksClientHandler());
}

From source file:org.msgpack.rpc.loop.netty.NettyTcpClientTransport.java

License:Apache License

NettyTcpClientTransport(TcpClientConfig config, Session session, NettyEventLoop loop,
        Class<? extends RpcMessageHandler> rpcHandlerClass) {
    super(config, session);

    try {//from   w  ww .  j  a  va  2s. c  o  m
        handler = rpcHandlerClass.getConstructor(Session.class).newInstance(session);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    //      handler = new RpcMessageHandlerEx(session);
    eventLoop = loop;
    bootstrap = new Bootstrap().group(group);
    bootstrap.channel(NioSocketChannel.class);
    final NettyTcpClientTransport trans = this;
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            if (isSocks) {
                p.addFirst("socks-handler", new SocksProxyHandler(session, trans));
                p.addFirst("socks-encode", new SocksMessageEncoder());
                p.addFirst("socks-decode", new SocksInitResponseDecoder());
            }
            p.addLast("msgpack-decode-stream", new MessagePackStreamDecoder(eventLoop.getMessagePack()));
            p.addLast("msgpack-encode", new MessagePackEncoder(eventLoop.getMessagePack()));
            p.addLast("message", new MessageHandler(handler, trans));
        }

    });
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
}