Open a non-blocking server channel and accept without waiting
Open a non-blocking server channel and accept without waiting
Answer
ServerSocketChannel server = ServerSocketChannel.open(); server.bind(new InetSocketAddress(7)); server.configureBlocking(false); SocketChannel client = server.accept();
open() only creates the object — bind() is what starts it listening, and accept() before bind() throws NotYetBoundException. After configureBlocking(false), accept() returns null rather than waiting, so the very next line must test for null.
Harold 4e ch11 §Channels