我正在尝试向客户端发送数据包,但我注意到即使我没有设置初始容量也没有错误。
// data is another ByteBuf object
// With capacity
ByteBuf d = Unpooled.buffer(2 + data.array().length);
d.writeByte(identifiers[0]).writeByte(identifiers[1]).writeBytes(data.array());
// Without capacity
ByteBuf d = Unpooled.buffer();
d.writeByte(identifiers[0]).writeByte(identifiers[1]).writeBytes(data.array());
这两者有什么区别吗?他们两个似乎都工作得很好。
我还想知道我是否做得对,我正在创建一个新的ByteBufwith Unpooled.buffer,在其中写入我的数据并channel.write(ByteBuf)在需要向客户端发送某些内容时将其发送到通道。我做得对吗?
繁花如伊
元芳怎么了
牧羊人nacy
相关分类