相关疑难解决方法(0)

Netty java从ByteBuf获取数据

如何ByteBuf在下面的代码中有效地获取字节数组?我需要获取数组然后序列化它.

package testingNetty;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ServerHandler extends  ChannelInboundHandlerAdapter {
     @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) {
         System.out.println("Message receive");
         ByteBuf buff = (ByteBuf) msg;
             // There is I need get bytes from buff and make serialization
         byte[] bytes = BuffConvertor.GetBytes(buff);
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { 
            // Close the connection when an exception is raised.
            cause.printStackTrace();
            ctx.close();
        }

}
Run Code Online (Sandbox Code Playgroud)

java netty

22
推荐指数
2
解决办法
3万
查看次数

标签 统计

java ×1

netty ×1