# io.github.libtmux.control.ControlClient.ControlClient

- **Module:** io.github.libtmux.control.ControlClient
- **Package:** io.github.libtmux:libtmux
- **Language:** Java
- **Kind:** class
- **Source:** https://github.com/libtmux/libtmux-java/blob/842228310449e879ebcaa3f910597757c9dbffd6/libtmux/src/main/java/io/github/libtmux/control/ControlClient.java#L54
- **Page:** https://libtmux.org/en/java/latest/reference/io-github-libtmux-control-controlclient-controlclient/

A tmux client that stays attached and answers one command at a time.

This is what a semicolon group cannot be. tmux discards a group after its first failure, so a
client has to infer which command failed; here each request is independent and each reply carries
the request number that produced it, so a failure discards nothing behind it and attribution is
tmux's own.

Replies arrive in request order, so the writer sends one request at a time and matches its
reply by position. A deadline before the writer picks a request writes nothing; a deadline after
that point ends the client because the next reply could no longer be attributed safely.

The reader and writer are platform threads. A library does not own the virtual-thread
scheduler, and either one unable to run stops the client from making progress. The reader only
resolves replies and fills bounded subscription buffers; subscriber code runs on the thread that
pulls a value.

**Threads.** {@link #send} may be called from several threads at once: requests
queue in the order they arrive and each caller gets its own reply. A subscription is read by one
thread at a time.

**Close it.** The client holds an attached tmux client, which is what makes tmux
push output to it, and closing is what detaches that client and stops its threads. A client that
is forgotten does not hold the JVM open — its threads are daemons — and the attached tmux client
exits once the JVM does, because it reads its commands from a pipe that closes with it. Until then
it is listed among the session's clients like any other.

## Members

- `attach` (method): Attaches a control client to an existing session.
- `send` (method): Runs one command and waits for its reply.
- `isAlive` (method): Whether the client is still running.
- `subscribeOutput` (method): Subscribes to terminal output tmux pushes.
- `subscribeEvents` (method): Subscribes to state changes tmux volunteers.
- `watch` (method): Asks tmux to report a format whenever its value changes.
- `unwatch` (method): Stops a watch. tmux reads a name with no colon in it as one to remove.
- `close` (method): Ends the client, rejecting queued requests and resolving picked requests as uncertain.
- `line` (method): tmux parses a control-mode request as one line, so an argument has to survive its lexer. Single quotes preserve everything except a single quote, which is closed, escaped and reopened.
- `unescape` (method): tmux writes a byte it cannot print as a three-digit octal escape.
