public void channelRead(ChannelHandlerContext ctx , Object msg) throws Exception {
ByteBuf msg1 = (ByteBuf) msg;
System.out.println(msg1.toString(Charset.defaultCharset()));
ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer();
byteBuf.writeBytes(msg1);
ctx.writeAndFlush(byteBuf);
}
这是正确写法
@Override
public void channelRead(ChannelHandlerContext ctx , Object msg) throws Exception {
ByteBuf msg1 = (ByteBuf) msg;
System.out.println(msg1.toString());
ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer();
byteBuf.getByte(Integer.valueOf(msg1.toString()).byteValue());
ctx.writeAndFlush(byteBuf);
}
这是错误写法
会导致无法写出,并且不会报错,原因不知道,希望有人能解释一下