0
私はTCindでSendind LogRecordというアプリケーションを持っており、このログを取りたいと思っています。私はNettyで新しく、いくつかの例で習った後、LogRecordオブジェクトを読むことができません。NettyでLogRecordを受信するにはどうすればよいですか?
オブジェクトを逆シリアル化するためにバイトの配列を取得しようとしましたが、エラーが発生します。誰かが私に良い事例やヒントを教えることができます。ここで
@Component
@Qualifier("socketChannelInitializer")
public class SocketChannelInitializer extends ChannelInitializer<SocketChannel> {
private static final ByteArrayDecoder DECODER = new ByteArrayDecoder();
private static final ByteArrayEncoder ENCODER = new ByteArrayEncoder();
@Autowired
@Qualifier("socketServerHandler")
private ChannelInboundHandlerAdapter socketServerHandler;
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
// Add the text line codec combination first,
pipeline.addLast(new DelimiterBasedFrameDecoder(1024 * 1024, Delimiters.lineDelimiter()));
// the encoder and decoder are static as these are sharable
pipeline.addLast(DECODER);
pipeline.addLast(ENCODER);
pipeline.addLast(socketServerHandler);
}
}
はハンドラの一部である:ここで
はコードである@Override
protected void channelRead0(ChannelHandlerContext ctx, byte[] msg) throws Exception {
ByteBuffer byteBuffer = ByteBuffer.wrap(msg).asReadOnlyBuffer();
}