My client-side pipeline (Client can send any type of messages i.e. HTTP 
requests, or binary packets. )

Bootstrap bootstrap = new Bootstrap()
        .group(group)
     //   .option(ChannelOption.TCP_NODELAY, true)
    //    .option(ChannelOption.SO_KEEPALIVE, true)
        .channel(NioSocketChannel.class)
        .handler(new ChannelInitializer() {
            @Override
            protected void initChannel(Channel channel) throws Exception {
                channel.pipeline()
                        .addLast("agent-traffic-shaping", ats)
                        .addLast("length-decoder", new 
LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4))
                        .addLast("agent-client", new AgentClientHandler())
                        .addLast("4b-length", new LengthFieldPrepender(4))
                ;
            }
        });


------------------------------ Server-side pipeline-----------------

ServerBootstrap b = new ServerBootstrap()
        .group(group)
  //      .option(ChannelOption.TCP_NODELAY, true)
 //       .option(ChannelOption.SO_KEEPALIVE, true)
        .channel(NioServerSocketChannel.class)
        .localAddress(new InetSocketAddress(port))
        .childHandler(new ChannelInitializer() {
                          @Override
                          protected void initChannel(Channel channel) throws 
Exception {
                              channel.pipeline()
                                      .addLast("agent-traffic-shaping", ats)
                                      .addLast("length-decoder", new 
LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4))
                                      .addLast(new AgentServerHandler())
                                      .addLast("4b-length", new 
LengthFieldPrepender(4));
                          }
                      }

        );

ChannelFuture f = b.bind().sync();
log.info("Started agent-side server at Port {}", port);


-------- Server's channelRead method-----------------



@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {

    ByteBuf data = (ByteBuf) msg;
    log.info("SIZE {}", data.capacity());
    String s = data.readCharSequence(data.capacity(), 
Charset.forName("utf-8")).toString();
    System.out.print(s);
    if (buffer != null) buffer.incomingPacket((ByteBuf) msg);
    else {
        log.error("Receiving buffer NULL for Remote Agent {}:{} ", 
remoteAgentIP, remoteAgentPort);
        ((ByteBuf) msg).release();
    }
 /*   totalBytes += ((ByteBuf) msg).capacity();*/
}



------------ Client writing on Channel----------------------------------

ByteBuf data contains valid HTTP request with size of 87 Bytes


private void writeToAgentChannel(Channel currentChannel, ByteBuf data) {

    String s = data.readCharSequence(data.capacity(), 
Charset.forName("utf-8")).toString();
    log.info("SIZE {}", data.capacity());
    System.out.print(s);

    ChannelFuture cf = currentChannel.write(data);
    currentChannel.flush();

 /*   wCount++;
    if (wCount >= request.getRequest().getBufferSize() * 
request.getRequest().getNumParallelSockets()) {
        for (Channel channel : channels)
            channel.flush();
        wCount = 0;
    }*/
    cf.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture channelFuture) throws 
Exception {
            if (cf.isSuccess()) {
                totalBytes += data.capacity();
            }
            else log.error("Failed to write packet to channel {}", cf.cause());
        }
    });
}



However Agent receives an empty ByteBuf with size of zero. What could be 
possible cause here?



-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/1c48dbe7-aba5-4029-b94f-b934175163ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to