NIOServer { void startServer() throws IOException { SelectorLoop connectionBell = new SelectorLoop(); readBell = new SelectorLoop(); ServerSocketChannel ssc = ServerSocketChannel.open(); ssc.configureBlocking(false); ServerSocket socket = ssc.socket(); socket.bind(new InetSocketAddress("localhost", SOCKET_PORT)); ssc.register(connectionBell.getSelector(), SelectionKey.OP_ACCEPT); new Thread(connectionBell).start(); }    }
@Test public void server() throws Exception { new NIOServer().startServer(); new Thread(new NIOClient()).start(); Thread.sleep(20); }