本文共 1143 字,大约阅读时间需要 3 分钟。
io.netty.handler.codec.serialization.ObjectDecoder
将ByteBuf[]反序列化为java对象。 A decoder which deserializes the received ByteBufs into Java objects. io.netty.handler.codec.serialization.ObjectEncoder 编码器,将java对象序列化为一个netty的ByteBuf对象。 An encoder which serializes a Java object into a ByteBuf. 要求传送的类实现java.io.serializable接口。用法见下。Bootstrap b = new Bootstrap(); b.handler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)), new TcpClientHandler()); } });
完整的项目示例见github。
https://github.com/chuchu9293/NettyTcpObjOrdering转载地址:http://fqkul.baihongyu.com/