【NIO服务器代码-可测试】
1、目的:了解NIO服务的工作原理 2、代码: /** * @Author: Liu * @Descripition:NIO测试 * @Date; Create in 2020/3/14 16:10 **/ public class NIOServerDemo { private int port = 8080; private Selector selector; private ByteBuffer buffer = ByteBuffer.allocate(1024); //初始化完毕 public NIOServerDemo(int port) { this.port = port; try { ServerSocketChannel server = ServerSocketChannel.open(); server.bind(new InetSocketAddress(this.port)); //设置非阻塞 server.configureBlocking(false); selector = Selector.open(); server.register(selector, SelectionKey.OP_ACCEPT); } catch (IOException e) { e.printStackTrace(); } } public void listen()