protected void awaitAccept() throws IOException {
  final Selector serverSelector=Selector.open();
  try {
    final SelectionKey serverKey=server.register(serverSelector,SelectionKey.OP_ACCEPT);
    try {
      serverSelector.select();
      final Set<SelectionKey> keys=serverSelector.selectedKeys();
      final Iterator<SelectionKey> iter=keys.iterator();
      while (iter.hasNext()) {
        final SelectionKey key=(SelectionKey)iter.next();
        iter.remove();
        if (key != serverKey)         throw new AssertionError();
        break;
      }
    }
  finally {
      serverKey.cancel();
    }
  }
  finally {
    serverSelector.close();
  }
}

protected void awaitAccept ( ) throws IOException { final Selector serverSelector = Selector . open ( ) ; try { final SelectionKey serverKey = server . register ( serverSelector , SelectionKey . OP_ACCEPT ) ; try { serverSelector . select ( ) ; final Set < SelectionKey > keys = serverSelector . selectedKeys ( ) ; final Iterator < SelectionKey > iter = keys . iterator ( ) ; while ( iter . hasNext ( ) ) { final SelectionKey key = ( SelectionKey ) iter . next ( ) ; iter . remove ( ) ; if ( key != serverKey ) throw new AssertionError ( ) ; break ; } } finally { serverKey . cancel ( ) ; } } finally { serverSelector . close ( ) ; } }
blocking wait for a client connection .
