tunnelcat-sdk docs
Docs / Language SDKs / C#

C# SDK

sdk/csharp is a thin client for tunneld's JSON-RPC protocol. It spawns tunneld via System.Diagnostics.Process and talks to it over a Unix domain socket via System.Net.Sockets.Socket with AddressFamily.Unix (supported on Windows since .NET Core 3.0+, always on Linux/macOS).

Build

cd sdk/csharp/TunnelCat.Sdk
dotnet build

You also need a built tunneld binary on your PATH:

go build -o tunneld ./cmd/tunneld   # from the repo root (add .exe on Windows)

Usage

using TunnelCat.Sdk;

using var client = new TunnelClient();
client.Start();
var result = client.Connect(new ConnectParams(
    Server: "https://your-control-server:443", Username: "you", Password: "secret"));
Console.WriteLine(result?["socksAddr"]);
client.Disconnect();

Try it with zero real credentials

go run ./cmd/mockserver &
cd sdk/csharp/examples/Basic
dotnet run

API reference

class TunnelException : Exception

Thrown when tunneld returns an {"error": ...} response, or on transport failure.

record ConnectParams

record ConnectParams( string Server, string ApiKey = "", string Username = "", string Password = "", string SocksAddr = "", bool PollingOnly = false )

PollingOnly: cmd/mockserver (and tunnelcat-server's own test stub) only support polling mode — see Wire Protocol.

sealed class TunnelClient : IDisposable

TunnelClient( string? tunneldPath = null, string? socketPath = null, Action<JsonObject>? onEvent = null, TimeSpan? connectTimeout = null)

Same shape as the other adapters. connectTimeout defaults to 5 seconds if not specified.

void Start()

Spawns tunneld with stdout/stderr redirected, waits for its socket file, connects, and starts a background reader thread. Throws TunnelException on failure to spawn, early process exit, or socket-wait timeout.

JsonObject? Connect(ConnectParams p)

Blocks up to a 15-second default timeout for the IPC response.

JsonObject? Disconnect()

JsonObject? Status()

JsonObject? Reconnect()

void Dispose()

Closes the socket and kills the entire tunneld process tree (Process.Kill(entireProcessTree: true), waits up to 5s), then deletes the socket file. Safe to call via using/using var as shown above.

Package

PackageId TunnelCat.Sdk, targeting .NET 8, currently versioned 0.1.0 — a first release, no published NuGet feed referenced in the repo yet.