0
public class Response{
  public int packetLength;
  public int cmd;
  public int seqId;
  public FileRegion fileRegion; //file content
  public String filename;
  public int begin;
  public int end;
  public String otherExtra;

  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e){  
    if(e.getMessage() instanceof Request){
        Request request = Request(e.getMessage());
        Channel ch = e.getChannel();
        Response response = new Response();
        response.cmd   = 111;
        response.seqId = 111;
        response.begin = 0;
        response.end   = 256;
        response.fileRegion = new DefaultFileRegion(GetFile().getChannel(),response.begin, response.end);
        response.filename = "test";
        response.otherExtra = "service"
        ch.write(response);
    }
  }
}

I need to use zero-copy (os level) to send data in a field of a network packet. netty support FileRegion and ChannelBuffer in these two types of data transmission. But now I want these two kinds of types of data together to form a packet.

How to solve Or how to write the above code encoder function?

Liuda
  • 1
  • 2

1 Answers1

0
  synchronized(mutex){
      ch.write("11111111");
      ch.write("222222");
      ch.write(region).addListener(lister);
      ch.write("333333");
  }

I thought of a way to lock in channel.write time. This ensures that the transmitted data is sequential, the sequence of the data transmitted when the network layer, the application layer into a complete network packet.

| 1111 | zero-copy data | 2222 |

Data received from the application layer

| 1111 | 45678 | 2222 |

Liuda
  • 1
  • 2