private void ensureOpen() throws IOException {
        if (channel == null || !channel.isOpen()) {
            try {
                reconnect();
            } catch (ConnectException e) {
                sleep(1000);
                throw e;
            }
        }
    }