netty学习笔记
Server:
bootstrap.option(ChannelOption.SO_BACKLOG,100)
private final ByteBuf firstMessage;
firstMessage = Unpooled.buffer(EchoClient.SIZE);
for(int i = 0; i<sendNumber; i++){
firstMessage.writeByte((byte)i);
}
Server:
// 以("\n")为结尾分割的 解码器
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
// 字符串解码和编码
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
//自己的逻辑Handler
pipeline.addLast("handler", new HelloServerHandler());
Client:
/*
* 这个地方的 必须和服务端对应上。否则无法正常解码和编码
*/
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
pipeline.addLast("handler", new HelloClientHandler());
ByteBuf与java的ByteBuffer类似,Byte数组的缓冲区。
ByteBufAllocator,字节缓冲区分配器
Future 获取异步操作的结果,异步操作的通知回调。
Promise是可写的Future