recently, I have been learning about java nio, which has been a bit strange. There is such a common code in nio programming
.for(xxxxxxx){
if(selectionKey.isAcceptable()){
ServerSocketChannel ssc = (ServerSocketChannel) selectionKey.channel();
SocketChannel socketChannel = ssc.accept();
socketChannel.configureBlocking(false);
socketChannel.register(selector,SelectionKey.OP_READ);
}
f(selectionKey.isReadable()){
.......
}
}
Loop scan the state of the channel. When the channel accept, a new channel socketChannel, will be generated and then the listening event will be specified. Such a tcp connection will form a channel,. Ask whether this is understood
.