Xcsb.Connection
1.0.2-beta
dotnet add package Xcsb.Connection --version 1.0.2-beta
NuGet\Install-Package Xcsb.Connection -Version 1.0.2-beta
<PackageReference Include="Xcsb.Connection" Version="1.0.2-beta" />
<PackageVersion Include="Xcsb.Connection" Version="1.0.2-beta" />
<PackageReference Include="Xcsb.Connection" />
paket add Xcsb.Connection --version 1.0.2-beta
#r "nuget: Xcsb.Connection, 1.0.2-beta"
#:package Xcsb.Connection@1.0.2-beta
#addin nuget:?package=Xcsb.Connection&version=1.0.2-beta&prerelease
#tool nuget:?package=Xcsb.Connection&version=1.0.2-beta&prerelease
Xcsb.Connection
⚠️ Warning: Xcsb.Connection is currently in early development. APIs are subject to change, and not all functionality is implemented. Use in production environments is not recommended.
Overview
Xcsb.Connection is the core connection library for XCSB, providing low-level protocol implementation for communicating with XServers. This library handles all aspects of establishing and maintaining connections to X servers, including authentication, handshake negotiation, and socket management.
Unlike traditional X11 bindings that wrap libX11 or xcb, Xcsb.Connection implements the X11 protocol directly in pure C#, enabling .NET developers to build cross-platform desktop applications without native dependencies.
Features
- Pure .NET Implementation: Zero dependencies on native X11 libraries (
libX11,xcb) - Direct Protocol Access: Implements the X11 protocol specification directly in C#
- Flexible Authentication: Supports MIT-MAGIC-COOKIE-1 authentication via
.Xauthorityfiles - Multiple Connection Types: TCP/IP and Unix domain socket support
- Cross-Platform: Works on Windows (via Xming/WSLg), Linux, and macOS (via XQuartz)
- Strongly Typed: Idiomatic .NET interfaces for compile-time safety
- Modern .NET: Targets .NET Standard 2.1, .NET 8.0, and .NET 9.0
Installation
Install via NuGet:
dotnet add package Xcsb.Connection
Or add directly to your .csproj file:
<PackageReference Include="Xcsb.Connection" Version="1.0.1-beta" />
Quick Start
Basic Connection
The simplest way to connect to an X server:
using Xcsb.Connection;
// Connect to the default X server (reads from DISPLAY environment variable)
using var connection = XcsbClient.Connect();
// Check connection status
if (connection.HandshakeSuccessResponseBody != null)
{
Console.WriteLine("Connected successfully!");
var screen = connection.HandshakeSuccessResponseBody.Screens[0];
Console.WriteLine($"Screen size: {screen.WidthInPixels}x{screen.HeightInPixels}");
}
else
{
Console.WriteLine($"Connection failed: {connection.FailReason}");
}
Specifying a Display
Connect to a specific X display:
// Connect to display :1
using var connection = XcsbClient.Connect(":1");
// Connect to a remote X server
using var connection = XcsbClient.Connect("tcp/192.168.1.100:0");
// Connect via Unix socket
using var connection = XcsbClient.Connect("/tmp/.X11-unix/X0:0");
Custom Authentication
Provide custom authentication credentials:
byte[] authName = "MIT-MAGIC-COOKIE-1"u8.ToArray();
byte[] authData = GetAuthCookie(); // Your authentication cookie
using var connection = XcsbClient.Connect(":0", authName, authData);
Creating a Window
Once connected, you can start creating windows and interacting with the X server:
using Xcsb;
using Xcsb.Connection;
using Xcsb.Masks;
using Xcsb.Models;
// Connect to the X Server
using var connection = XcsbClient.Connect();
var xcsb = connection.Initialized();
var screen = connection.HandshakeSuccessResponseBody.Screens[0];
// Basic Event Loop
while (true)
{
var evnt = xcsb.GetEvent();
if (evnt.ReplyType == XEventType.KeyPress)
{
break; // Exit on key press
}
}
Display String Format
The library supports various display string formats:
| Format | Description | Example |
|---|---|---|
:N |
Local display N (Unix socket) | :0, :1 |
:N.S |
Local display N, screen S | :0.0, :1.1 |
host:N |
TCP connection to host, display N | localhost:0 |
tcp/host:N |
Explicit TCP connection | tcp/192.168.1.100:0 |
/path:N |
Unix socket at specific path | /tmp/.X11-unix/X0:0 |
Authentication
Automatic Authentication
By default, XcsbClient.Connect() automatically:
- Looks for the
XAUTHORITYenvironment variable - Falls back to
$HOME/.Xauthority - Reads MIT-MAGIC-COOKIE-1 authentication data
- Attempts connection with discovered credentials
Manual Authentication
For custom authentication scenarios:
byte[] authName = System.Text.Encoding.UTF8.GetBytes("MIT-MAGIC-COOKIE-1");
byte[] authData = /* your 16-byte cookie */;
using var connection = XcsbClient.Connect(":0", authName, authData);
Configuration
Customize connection behavior with XcsbClientConfiguration:
var config = new XcsbClientConfiguration
{
ShouldCrashOnFailConnection = true // Throw exception on connection failure
};
using var connection = XcsbClient.Connect(":0", config);
Requirements
- .NET Standard 2.1, .NET 8.0, or .NET 9.0
- X Server:
Error Handling
The library provides detailed error information:
using var connection = XcsbClient.Connect(":0");
if (connection.HandshakeSuccessResponseBody == null)
{
Console.WriteLine($"Connection failed: {connection.FailReason}");
// Handle connection failure
}
Common failure reasons:
- Authentication failed: Invalid or missing
.Xauthoritycredentials - Connection refused: X server not running or not accepting connections
- Display not found: Invalid display number or socket path
Accessing Screen Information
var handshake = connection.HandshakeSuccessResponseBody;
if (handshake != null)
{
foreach (var screen in handshake.Screens)
{
Console.WriteLine($"Screen: {screen.WidthInPixels}x{screen.HeightInPixels}");
Console.WriteLine($"Root Window: {screen.Root}");
Console.WriteLine($"Default Colormap: {screen.DefaultColormap}");
Console.WriteLine($"Root Visual: {screen.RootVisualId}");
}
}
Examples
For complete examples demonstrating various features, check the Examples directory in the repository:
- Basic window creation
- Event handling
- Graphics operations
- Multi-screen applications
Project Structure
Xcsb.Connection/
├── Configuration/ # Connection configuration options
├── Handlers/ # Socket access and communication handlers
├── Helpers/ # Utility classes for protocol operations
├── Infrastructure/ # Core connection and handshake logic
├── Models/ # Protocol data structures and models
│ └── Handshake/ # Handshake-specific models
├── IXConnection.cs # Public connection interface
├── IXConnectionInternal.cs # Internal connection interface
└── XcsbClient.cs # Main entry point
Contributing
Contributions are welcome! When contributing to Xcsb.Connection:
- Fork the repository
- Create a feature branch (
git checkout -b feature/ConnectionFeature) - Commit your changes (
git commit -m 'Add connection feature') - Push to the branch (
git push origin feature/ConnectionFeature) - Open a Pull Request
Please reference the X11 Protocol Specification when implementing protocol features.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Resources
Support
For issues, questions, or contributions:
- GitHub Issues: https://github.com/ovpoddar/XCSB/issues
- Repository: https://github.com/ovpoddar/XCSB
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Xcsb.Connection:
| Package | Downloads |
|---|---|
|
Xcsb
Xcsb is a .NET library that lets you talk directly to the x-server Window System. For .NET developers, this means you can build cross-platform desktop apps that interact with X11 servers. |
|
|
Xcsb.Extension.BigRequests
Xcsb.Extension.BigRequests is part of the Xcsb extension family and enables Big Requests support for Xcsb-based applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.0.2-beta | 45 | 5/17/2026 | |
| 1.0.1-beta | 57 | 4/30/2026 | |
| 1.0.0-beta | 68 | 3/26/2026 |