Example usage for io.netty.handler.codec LengthFieldBasedFrameDecoder LengthFieldBasedFrameDecoder

List of usage examples for io.netty.handler.codec LengthFieldBasedFrameDecoder LengthFieldBasedFrameDecoder

Introduction

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

Prototype

public LengthFieldBasedFrameDecoder(ByteOrder byteOrder, int maxFrameLength, int lengthFieldOffset,
        int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, boolean failFast) 

Source Link

Document

Creates a new instance.

Usage

From source file:com.eightkdata.mongowp.mongoserver.MongoServer.java

License:Open Source License

private void buildChildHandlerPipeline(ChannelPipeline pipeline) {
    pipeline.addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, MongoWP.MAX_MESSAGE_SIZE_BYTES,
            0, MongoWP.MESSAGE_LENGTH_FIELD_BYTES, -MongoWP.MESSAGE_LENGTH_FIELD_BYTES,
            MongoWP.MESSAGE_LENGTH_FIELD_BYTES, true));
    pipeline.addLast(new RequestMessageByteHandler());
    pipeline.addLast(new LengthFieldPrependerLittleEndian(MongoWP.MESSAGE_LENGTH_FIELD_BYTES, true));
    pipeline.addLast(new ReplyMessageObjectHandler(this));
    pipeline.addLast(new RequestMessageObjectHandler(requestProcessor));
}

From source file:com.eightkdata.mongowp.server.wp.NettyMongoServer.java

License:Open Source License

private void buildChildHandlerPipeline(ChannelPipeline pipeline) {
    pipeline.addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN,
            MongoConstants.MAX_MESSAGE_SIZE_BYTES, 0, MongoConstants.MESSAGE_LENGTH_FIELD_BYTES,
            -MongoConstants.MESSAGE_LENGTH_FIELD_BYTES, MongoConstants.MESSAGE_LENGTH_FIELD_BYTES, true));
    pipeline.addLast(requestMessageByteHandler.get());
    pipeline.addLast(lengthFieldPrependerLittleEndian);
    pipeline.addLast(replyMessageObjectHandler.get());
    pipeline.addLast(requestMessageObjectHandler);
}

From source file:com.l2jmobius.gameserver.network.client.ClientInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) {
    final L2GameClient client = new L2GameClient();
    ch.pipeline().addLast("length-decoder",
            new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 0x8000 - 2, 0, 2, -2, 2, false));
    ch.pipeline().addLast("length-encoder", LENGTH_ENCODER);
    ch.pipeline().addLast("crypt-codec", new CryptCodec(client.getCrypt()));
    // ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
    ch.pipeline().addLast("packet-decoder",
            new PacketDecoder<>(ByteOrder.LITTLE_ENDIAN, IncomingPackets.PACKET_ARRAY, client));
    ch.pipeline().addLast("packet-encoder", PACKET_ENCODER);
    ch.pipeline().addLast(client);// ww w. j  a v  a 2  s. c om
}

From source file:com.l2jmobius.gameserver.network.loginserver.LoginServerInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) {
    final LoginServerHandler loginServerHandler = new LoginServerHandler();
    ch.pipeline().addLast("length-decoder",
            new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 0x8000 - 2, 0, 2, -2, 2, false));
    ch.pipeline().addLast("length-encoder", LENGTH_ENCODER);
    // ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
    ch.pipeline().addLast("packet-decoder",
            new PacketDecoder<>(ByteOrder.LITTLE_ENDIAN, IncomingPackets.PACKET_ARRAY, loginServerHandler));
    ch.pipeline().addLast("packet-encoder", PACKET_ENCODER);
    ch.pipeline().addLast(loginServerHandler);
}

From source file:de.dfki.kiara.tcp.TcpClientInitializer.java

License:Open Source License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();/*  w  w w  .  j av  a  2  s .  c  o m*/
    // Enable TCPS if necessary.
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    p.addLast("logger", new LoggingHandler(LogLevel.DEBUG));

    p.addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, Integer.MAX_VALUE, 0, 4, 0, 4, true));
    p.addLast(new ByteBufferDecoder());

    p.addLast(new LengthFieldPrepender(4, 0, false) {
        @Override
        protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
            ByteBuf outWithLittleEndian = out.order(ByteOrder.LITTLE_ENDIAN);
            super.encode(ctx, msg, outWithLittleEndian);
        }
    });
    p.addLast(new ByteBufferEncoder());
    p.addLast(handler);
}

From source file:de.dfki.kiara.tcp.TcpServerInitializer.java

License:Open Source License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();/* w w  w  . j  ava2s .c om*/
    // Enable TCPS if necessary.
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    p.addLast("logger", new LoggingHandler(LogLevel.DEBUG));

    p.addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, Integer.MAX_VALUE, 0, 4, 0, 4, true));
    p.addLast(new ByteBufferDecoder());

    p.addLast(new LengthFieldPrepender(4, 0, false) {
        @Override
        protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
            ByteBuf outWithLittleEndian = out.order(ByteOrder.LITTLE_ENDIAN);
            super.encode(ctx, msg, outWithLittleEndian);
        }
    });
    p.addLast(new ByteBufferEncoder());
    p.addLast(new TcpHandler(transport, connectionListener));
}

From source file:io.horizondb.client.ConnectionManager.java

License:Apache License

/**
 * //from w w  w.  j  a  va2  s  .  co m
 */
public ConnectionManager(ClientConfiguration configuration) {

    this.configuration = configuration;
    this.bootstrap = new Bootstrap().group(new NioEventLoopGroup()).channel(NioSocketChannel.class)
            .option(ChannelOption.TCP_NODELAY, Boolean.TRUE).handler(new ChannelInitializer<SocketChannel>() {

                @Override
                public void initChannel(SocketChannel ch) throws Exception {

                    int adjustment = MsgHeader.HEADER_SIZE
                            - (MsgHeader.LENGTH_FIELD_OFFSET + MsgHeader.LENGTH_FIELD_LENGTH);

                    ch.pipeline().addLast("encoder", new MsgToByteEncoder())
                            .addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN,
                                    Integer.MAX_VALUE, MsgHeader.LENGTH_FIELD_OFFSET,
                                    MsgHeader.LENGTH_FIELD_LENGTH, adjustment, 0, true))
                            .addLast("client", new ClientHandler());
                }
            });
}

From source file:org.fiware.kiara.transport.tcp.TcpServerInitializer.java

License:Open Source License

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();/*  ww w  .  jav a 2s. c om*/
    // Enable TCPS if necessary.
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    p.addLast("logger", new LoggingHandler(LogLevel.DEBUG));

    p.addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, Integer.MAX_VALUE, 0, 4, 0, 4, true));
    p.addLast(new ByteBufferDecoder());

    p.addLast(new LengthFieldPrepender(4, 0, false) {
        @Override
        protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
            ByteBuf outWithLittleEndian = out.order(ByteOrder.LITTLE_ENDIAN);
            super.encode(ctx, msg, outWithLittleEndian);
        }
    });
    p.addLast(new ByteBufferEncoder());
    p.addLast(new TcpHandler(transportFactory, path, connectionListener));
}

From source file:org.l2junity.loginserver.network.client.ClientInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) {
    final SecretKey blowfishKey = KeyManager.getInstance().generateBlowfishKey();
    final ClientHandler clientHandler = new ClientHandler(blowfishKey);
    ch.pipeline().addLast("length-decoder",
            new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 0x8000 - 2, 0, 2, -2, 2, false));
    ch.pipeline().addLast("length-encoder", LENGTH_ENCODER);
    ch.pipeline().addLast("crypt-codec", new CryptCodec(new Crypt(blowfishKey)));
    // ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
    ch.pipeline().addLast("packet-decoder",
            new PacketDecoder<>(ByteOrder.LITTLE_ENDIAN, IncomingPackets.PACKET_ARRAY, clientHandler));
    ch.pipeline().addLast("packet-encoder", PACKET_ENCODER);
    ch.pipeline().addLast(clientHandler);
}

From source file:org.l2junity.loginserver.network.gameserver.GameServerInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) {
    final SecretKey blowfishKey = KeyManager.getInstance().generateBlowfishKey();
    ch.pipeline().addLast("length-decoder",
            new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 0x8000 - 2, 0, 2, -2, 2, false));
    ch.pipeline().addLast("length-encoder", LENGTH_ENCODER);
    ch.pipeline().addLast("crypt-codec", new CryptCodec(new Crypt(blowfishKey)));
    ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));

    final GameServerHandler gameServerHandler = new GameServerHandler();
    ch.pipeline().addLast("packet-decoder",
            new PacketDecoder<>(ByteOrder.LITTLE_ENDIAN, IncomingPackets.PACKET_ARRAY, gameServerHandler));
    ch.pipeline().addLast("packet-encoder", PACKET_ENCODER);
    ch.pipeline().addLast(gameServerHandler);
}