Home > Back-end >  The couple asked about netty under simple problems.
The couple asked about netty under simple problems.

Time:11-06

Read data from a machine, such as the speed of XX, XX, using netty access, and then passed on to other modules (the Java language to write)

The main code:
The bootstrap. ChildHandler (new ChannelInitializer () {
@ Override
Public void initChannel SocketChannel (ch) throws the Exception {
Ch. Pipeline (.) addLast (new ReadTimeoutHandler (90));
Ch. Pipeline (.) addLast (new DelimiterBasedFrameDecoder (204800, Unpooled copiedBuffer (new byte [] x7e {0})));
Ch. Pipeline (.) addLast (new ServerChannelHandlerAdapter ());
}
});


In the class ServerChannelHandlerAdapter extends ChannelInboundHandlerAdapter in public void channelRead (ChannelHandlerContext CTX, Object MSG) method, and there is a statement


For (ByteBuf ByteBuf: byteBufs) {
CTX. WriteAndFlush (byteBuf);
}

1. The speed, position the data should be within byteBuf, but how to get the data?
2. Write a python module, there seems to be no netty in python, the contents can be read from a python?

Try so hard to find a result, only saw netty1 hours, too late to learn, ask elder, speak a little bit colloquialism, thank you.

CodePudding user response:

 
Int readable=byteBuf. ReadableBytes ();
Byte [] MSG=new byte (readable);
Int index=byteBuf. ReaderIndex ();
In getBytes (index, MSG);

MSG is netty access to content, is now a byte type, into the type you need you can


  • Related