~/ learn/ comp-348/ cards/ Selectors: one thread, many connections
1 of 6

Register a channel and hand it its per-connection state

Register a channel and hand it its per-connection state

Answer

client.configureBlocking(false); SelectionKey key = client.register(selector, SelectionKey.OP_READ); key.attach(response.duplicate());

register() lives on the channel and requires non-blocking mode first. The attachment carries this connection state; duplicate() gives this client its own position and limit over the one shared response buffer.

Harold 4e ch11 §Readiness Selection

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/9ca7ecc8-9b69-4e64-a7c2-a637ff32760c/flashcard utf-8 LF