protected void start(boolean direct) throws Exception {
        selector=Selector.open();

        ch=ServerSocketChannel.open();
        ch.bind(new InetSocketAddress("0.0.0.0", 7500));
        ch.configureBlocking(false);
        ch.register(selector, SelectionKey.OP_ACCEPT, null);
        System.out.println("-- server ready");

        while(running) {
            selector.select();
            Set<SelectionKey> keys=selector.selectedKeys();
            for(Iterator<SelectionKey> it=keys.iterator(); it.hasNext();) {
                SelectionKey key=it.next();
                if(!key.isValid()) {
                    it.remove();
                    continue;
                }
                it.remove();
                if(key.isAcceptable()) {
                    SocketChannel client_ch=ch.accept();
                    if(client_ch != null) { // accept() may return null...
                        System.out.printf("accepted connection from %s\n", client_ch.getRemoteAddress());
                        client_ch.configureBlocking(false);
                        client_ch.register(selector, SelectionKey.OP_READ, create(SIZE, direct));
                    }
                }
                else if(key.isReadable()) {
                    if(!handle((SocketChannel)key.channel(), (ByteBuffer)key.attachment())) {
                        key.cancel();
                        Util.close(key.channel());
                    }
                }
            }
        }

        Util.close(selector,ch);
    }