tmuxtmuxTopics

Choose documentation 1

latest

tmux manual version

Latest (3.7c) 3.7c 3.2a
English

Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

Edit this page on GitHub

Socket and servers

A tmux server is selected by its Unix-domain socket. Use different sockets for independent servers, such as a development session and an isolated test server. Choose the default socket, a named socket (-L), or an explicit path (-S).

Naming a server

Python

Server() selects the default socket. Pass socket_name="work" to select a named socket, or socket_path="/tmp/tmux-1000/work" for an explicit path.

TypeScript

new Server() selects the default socket. Set socketName to select a named socket, or socketPath to use an explicit path.

Go

tmux.NewServer(tmux.ServerOptions{}) selects the default socket. Set ServerOptions.SocketName for a named socket or ServerOptions.SocketPath for an explicit path.

Rust

Server::new() selects the default socket. Use Server::builder().socket_name("work").build()? for a named socket or Server::builder().socket_path(path).build()? for an explicit path.

Java

ServerEndpoint.defaultSocket() selects the default socket. ServerEndpoint.namedSocket("work") selects a named socket, and ServerEndpoint.socketPath(path) selects an explicit path.

C#

new ServerConnectionOptions() selects the default socket. Supply socketName for a named socket or socketPath for an explicit path.

C++

Server::at_default() selects the default socket. Use Server::at_socket_name("work") for a named socket or Server::at_socket_path(path) for an explicit path.

Swift

Select a named socket with Server(socketName: "work") or an explicit path with Server(socketPath: path). The initializer requires a socket selection; see the default-socket example below.

default_server = libtmux.Server()
named = libtmux.Server(socket_name="work")

Choose either a socket name or a socket path. tmux uses TMUX_TMPDIR to resolve the directory for default and named sockets.

Supplying both selectors raises TypeError. ServerOptions.SocketPath takes precedence over ServerOptions.SocketName when both are set.

Swift requires an explicit socketPath or socketName argument. To reach tmux's default socket, use Server(socketName: "default").

Server(socket_name_factory=...) accepts a callable that generates socket names. Use a unique name for each isolated test server. ServerConnectionOptions(socketNameFactory: ...) accepts a callable that generates socket names. Use a unique name for each isolated test server.

Is the server actually there?

A server handle does not prove that the target server is running. Use a liveness check when your program needs to distinguish a live server from an unavailable socket:

Python

Server.is_alive returns a boolean indicating whether the server responds.

TypeScript

Server.isAlive returns a promise of a boolean. Server.raiseIfDead throws when the server is unavailable and retains the reason reported by tmux.

Go

Server.IsAlive returns (bool, error). The error reports a check that could not be completed; a false result alone means the server is not alive.

Rust

Server.is_alive returns a boolean. Use Server.check_alive when you also need to distinguish a failed check from a server that is not alive.

Java

Server.isAlive returns a boolean.

C#

Server.IsAliveAsync returns Task<bool>.

C++

Server.is_alive takes a timeout and returns a boolean.

Swift

Server.isRunning is an async throwing check that returns Bool.

if server.is_alive():
server.sessions

isAlive() returns a boolean. Use raiseIfDead() when you need failure details. is_alive() returns a boolean. Use check_alive() when you need failure details.

Killing a server, and telling two apart

Killing a server ends all its sessions. Use this only for a server your program owns; for narrower cleanup, kill the session or pane you created.

Call server.kill_server(). Server.__eq__ compares socket_name and socket_path when deciding whether two handles select the same endpoint. Call await server.kill(). TmuxServerRestartedError reports an operation whose handle encountered a replacement daemon on the same socket. Call server.Kill(ctx) and check its error. server.Equal(other) compares the captured socket bindings, resolving relative paths and environment-based socket names. Equal endpoints do not prove equal daemon lifetimes. ErrDaemonReplaced reports a replacement daemon on the selected socket. Call server.kill().await? and handle a cleanup failure before returning. Call server.killServer() to stop tmux. Server.close() releases the local connection and leaves tmux running; see Ownership and cleanup. Call await server.KillAsync() and handle a cleanup failure before returning. Call server.kill() and inspect its result for a failure. Call try await server.killServer() and handle a cleanup failure before returning.

A restarted server can reuse a socket path while having different state. Do not treat a matching path as proof that a cached object still exists.

Esc

Type to search.