参考文章:http://www.starmcu.com/archives/645
在客户端和服务端的Initializer里要注意顺序:
ProtobufEncoder要放在ProtobufVarint32LengthFieldPrepender后面。
public class MySixthClientInitializer extends ChannelInitializer<SocketChannel>{
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline channelPipeline = socketChannel.pipeline();
channelPipeline.addLast(new ProtobufVarint32FrameDecoder());
channelPipeline.addLast(new ProtobufDecoder(DataInfo.MyMessage.getDefaultInstance()));
channelPipeline.addLast(new ProtobufVarint32LengthFieldPrepender());
channelPipeline.addLast(new ProtobufEncoder());
channelPipeline.addLast(new MySixthClientHandler());
}
}
public class MySixthServerInitializer extends ChannelInitializer<SocketChannel>{
@Override
p