Server.ConnectAsync
Connects to a configured tmux endpoint.
Source and package
- Qualified name
-
LibTmux .Server. Connect Async - Namespace
- LibTmux
- Declared in
Server- Package
- LibTmux
- Source
- src/LibTmux/Server.Identity.cs
- static Task<Server> ConnectAsync( Server
Connection ? options = null, CancellationOptions Token cancellationToken = default )static Task<Server> ConnectAsync( CancellationToken cancellationToken = default ) -
- Parameters
-
-
options(ServerConnection ?) forOptions ConnectAsync(options, cancellationToken)Default
null -
cancellationToken(CancellationToken )Default
default
-
Examples
Distinguish an endpoint handle from a discovered server. Connection discovery returns an immutable replacement without capturing child relations. Use Linux or macOS with tmux 3.3a or newer, the .NET 10 SDK or newer, and the .NET 8 and 10 runtimes. In an empty directory, save this project as
Example.csproj. It references the 0.1.1 release ofLibTmuxon NuGet: View sourceExample.csproj <Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><OutputType>Exe</OutputType><TargetFrameworks>net8.0;net10.0</TargetFrameworks><LangVersion>12.0</LangVersion><Nullable>enable</Nullable><ImplicitUsings>disable</ImplicitUsings><EnableDefaultCompileItems>false</EnableDefaultCompileItems><TreatWarningsAsErrors>true</TreatWarningsAsErrors><AnalysisLevel>10-recommended</AnalysisLevel></PropertyGroup><ItemGroup><Compile Include="Program.cs" /><PackageReference Include="LibTmux" Version="[0.1.1]" /></ItemGroup></Project>Save this complete program as
Program.cs. It creates a private server;await usingdisposes its owned scopes after success, cancellation or failure. The complete file contains explicit imports, a top-level async entry point and a cancellation deadline. View sourceProgram.csComplete program using System;using System.IO;using System.Threading;using LibTmux;if (OperatingSystem.IsWindows()){throw new PlatformNotSupportedException("This example requires tmux on Linux or macOS.");}using CancellationTokenSource deadline = new(TimeSpan.FromSeconds(10));CancellationToken token = deadline.Token;string? testTmux = Environment.GetEnvironmentVariable("LIBTMUX_TEST_TMUX");string? configured = !string.IsNullOrWhiteSpace(testTmux)? testTmux: Environment.GetEnvironmentVariable("LIBTMUX_TMUX");string binary = string.IsNullOrWhiteSpace(configured) ? "tmux" : configured;using TemporaryDirectory socketRoot = new();ServerConnectionOptions options = new(){SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),ConfigurationFile = "/dev/null",TmuxBinaryPath = binary,};// Open records the endpoint without running tmux or reading its state.Server endpoint = Server.Open(options);if (endpoint.IsMaterialized){throw new InvalidOperationException("Open must not discover a server.");}await using OwnedServerScope owned = await Server.CreateOwnedAsync(options, token);await using OwnedSessionScope session = await owned.Value.CreateOwnedSessionAsync(new NewSessionRequest { Name = "demo", Command = "/bin/cat" }, token);// Connect discovers the live daemon and returns a new materialized handle.Server connected = await endpoint.ConnectAsync(token);Server sameEndpoint = await Server.ConnectAsync(options, token);if (!connected.IsMaterialized || !sameEndpoint.IsMaterialized || endpoint.IsMaterialized){throw new InvalidOperationException("Connecting must leave the original handle unchanged.");}if (connected.Generation != sameEndpoint.Generation || connected.Sessions.IsCaptured){throw new InvalidOperationException("Connection discovery must not capture the hierarchy.");}Console.WriteLine("Open records an endpoint; Connect discovers the running server.");Console.WriteLine("The original handle stays unmaterialized; relations remain uncaptured.");internal sealed class TemporaryDirectory : IDisposable{private readonly DirectoryInfo _directory = Directory.CreateTempSubdirectory("libtmux-example-");public string FullName => _directory.FullName;public void Dispose() => _directory.Delete(recursive: true);}Build the project and run both supported frameworks. Each program checks its result and exits unsuccessfully after an unhandled error:
Terminal window $ dotnet build Example.csproj --configuration Release && \dotnet bin/Release/net8.0/Example.dll && \dotnet bin/Release/net10.0/Example.dllExpected program output from each framework:
Open records an endpoint; Connect discovers the running server.The original handle stays unmaterialized; relations remain uncaptured.
Recorded calls
source callsThe C# reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls LibTmux.Server.ConnectAsync.