
nio
kong-kong
记录流水账
展开
-
Selector.select
创建SelectorSelector selector = Selector.open();selector.select()public int select() throws IOException { return this.select(0L);}原创 2021-09-30 15:15:31 · 401 阅读 · 0 评论 -
ServerSocketChannel
ServerSocketChannelImplServerSocketChannel.open()ServerSocketChannel channel = ServerSocketChannel.open();public static ServerSocketChannel open() throws IOException { return SelectorProvider.provider().openServerSocketChannel();}SelectorProvid原创 2021-09-30 14:51:44 · 326 阅读 · 0 评论 -
nio-ByteBuffer碰到的问题
ByteBuffer服务端接收不到OP_READ事件ByteBuffer byteBuffer = ByteBuffer.allocate(length);...............................sc.write(byteBuffer);通过allocate创建的ByteBuffer,需要调用下filp()方法,不调用,Server端就监听不到本次write的OP_READ事件ByteBuffer byteBuffer = ByteBuffer.wrap..原创 2020-07-22 17:32:54 · 379 阅读 · 0 评论 -
BigEndian和LittleEndian区别
MSB的意思是:全称为Most Significant Bit,在二进制数中属于最高有效位,MSB是最高加权位,与十进制数字中最左边的一位类似LSB的意思是:全称为Least Significant Bit,在二进制数中意为最低有效位,一般来说,MSB位于二进制数的最左侧,LSB位于二进制数的最右侧以数字0x01020304在两种不同字节序CPU中的存储顺序如下所示:Big Endian低地址...原创 2020-07-22 13:42:36 · 426 阅读 · 0 评论 -
NIO例子
client向server发送questionId,server随机得到1个答案,然后把questionId和答案发送给clientAnswerServerpublic class AnswerServer { private static AtomicLong atomicLong = new AtomicLong(); public static final String[] answers = {"A","B","C","D"}; public stat..原创 2020-07-21 18:25:04 · 249 阅读 · 0 评论 -
CharBuffer
public static void main(String[] args) { char[] array = new char[]{'a','b','c','d','e'}; CharBuffer buffer = CharBuffer.wrap(array); // 5 5 System.out.println("A capacity="+buffer.capacity()+" limit="+buffer.limit());...原创 2020-07-18 10:53:33 · 476 阅读 · 0 评论 -
循环报错: 远程主机强迫关闭了一个现有的连接
客户端终止后,服务端一直循环报java.io.IOException: 远程主机强迫关闭了一个现有的连接。原始代码private void read(SocketChannel channel,SelectionKey key) throws Exception { ByteBuffer buffer = ByteBuffer.allocate(1024); //创建...原创 2019-06-13 11:16:39 · 6061 阅读 · 0 评论 -
mark postion limit capacity
0<= mark <= position <= limit <= capacitylimit取值从0开始,capacity取值从1开始fliplimit = position;position = 0;mark = -1;rewindposition = 0;mark = -1;clearpositi...原创 2019-06-17 00:15:17 · 463 阅读 · 0 评论