Код: Выделить всё
final SelectionKey clientKey;
if (client.connect(_Rfc863Constants.SERVER_ENDPOINT)) {
log.debug("connected to {}", client.getRemoteAddress());
clientKey = client.register(selector, SelectionKey.OP_WRITE);
} else {
clientKey = client.register(selector, SelectionKey.OP_CONNECT);
}
_Rfc863Utils.readQuitAndCall(() -> {
clientKey.cancel(); //
Подробнее здесь: [url]https://stackoverflow.com/questions/79428852/can-any-of-selectedkeys-is-invalid[/url]