第四章:从零编写一个“玩具”项目
架构图
模块交互数据结构
Netty 编程中易错点解析
• LengthFieldBasedFrameDecoder 中initialBytesToStrip 未考虑设置
• ChannelHandler 顺序不正确
• ChannelHandler 该共享不共享,不该共享却共享
• 分配ByteBuf :分配器直接用ByteBufAllocator.DEFAULT 等,而不是采用ChannelHandlerContext.alloc()
• 未考虑ByteBuf 的释放
• 错以为ChannelHandlerContext.write(msg) 就写出数据了
• 乱用ChannelHandlerContext.channel().writeAndFlush(msg)
项目Demo地址
https://gitee.com/shao_yi_feng/netty.git