Code example for SelectionKey

Methods: channelselector

0
        this.buffer = buffer;
    } 
 
    public void react(SelectionKey key) throws IOException {
        try { 
            SocketChannel sc = (SocketChannel) key.channel();
            buffer.flip();
            int count = sc.write(buffer);
 
            if (!buffer.hasRemaining())
                // Nothing left to write: OK to start reading again 
                sc.register(key.selector(), SelectionKey.OP_READ, new Reader(buffer));
        } 
        finally { 
            buffer.compact();
        } 
    } 
} 
Experience pair programming with AI  Get Codota for Java