EnjoySockets 1.1.0

dotnet add package EnjoySockets --version 1.1.0
                    
NuGet\Install-Package EnjoySockets -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EnjoySockets" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EnjoySockets" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="EnjoySockets" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EnjoySockets --version 1.1.0
                    
#r "nuget: EnjoySockets, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EnjoySockets@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EnjoySockets&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=EnjoySockets&version=1.1.0
                    
Install as a Cake Tool

EnjoySockets

EnjoySockets is a high-performance C# library designed for TCP communication, with UDP support currently on the roadmap. It bridges the gap between low-level socket programming and overly complex frameworks, offering a "batteries-included" experience.

Why EnjoySockets?

While working on numerous client-server projects, I often found myself lacking a library that provided necessary functionality out of the box without massive boilerplate.

  • Performance-First: Built with a zero-allocation focus and full async support.
  • Resource Control: Robust flow control using System.Threading.Channels and object pooling.
  • Easy Adoption: High-level abstractions like RPC and session reconnection that don't require major refactoring.

Serialization & Models

The library leverages the MemoryPack engine for maximum efficiency.

Your message models must be marked as partial and have the [MemoryPackable] attribute. For advanced scenarios, refer to the MemoryPack documentation.

Installation

Install-Package EnjoySockets

Compatibility

EnjoySockets supports .NET 6 and .NET 8+, including Native AOT.

  • Recommendation: For maximum server-side performance, use .NET 8 or newer. This allows the JIT to perform hardware-specific optimizations that often outperform Native AOT in high-throughput scenarios.

Native AOT Configuration

To use Native AOT, add these sections to your .csproj and ensure you include the assembly containing your logic/message classes to prevent the trimmer from removing them:

<PropertyGroup>
  <PublishAot>true</PublishAot>
  <InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
  <TrimmerRootAssembly Include="EnjoySockets" />
  <TrimmerRootAssembly Include="YourProject.Logic" />
</ItemGroup>

Quick Start

EnjoySockets uses an intuitive routing engine: incoming messages are automatically routed to methods in your logic classes that match the message name.

Server Side

using EnjoySockets;

// You can generate a random key via ERSA.GeneratePrivatePublicPEM() or any other method.
// Keys should be stored securely.
string pemKeyPrivate = "-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----";
string pemKeyPrivateSign = "-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----";

var server = new ETCPServer(new(pemKeyPrivate, pemKeyPrivateSign));

if (server.Start(EAddress.Get()))
    Console.WriteLine("Server started successfully!");
else
    Console.WriteLine("Failed to start server.");

Console.ReadKey();

// Methods in logic classes are automatically invoked based on the message name string.
static class ExampleReceiveClassServer
{
    static void TestMethod(EUserServer user)
    {
        Console.WriteLine("Received 'TestMethod'. Sending response...");
        _ = user.Send("ResponseTestMethod", Random.Shared.Next());
    }
}

Client Side

using EnjoySockets;

// Ensure these public keys match the private keys used by the server.
string pemKeyPublic = "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----";
string pemKeyPublicSign = "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----";

var client = new EUserClient(new(pemKeyPublic, pemKeyPublicSign));
byte connectResult = await client.Connect(EAddress.Get());

if (connectResult == 0)
{
    // Sending a message triggers 'TestMethod' on the server
    await client.Send("TestMethod");
}
else
{
    Console.WriteLine($"Connection failed. Error code: {connectResult}");
    Console.ReadKey();
    return;
}

Console.ReadKey();

// Logic class: Handles responses from the server.
static class ExampleReceiveClassClient
{
    static void ResponseTestMethod(EUserClient user, int luckyNumber)
    {
        Console.WriteLine($"Your lucky number from server is: {luckyNumber}");
    }
}

Encryption & Security

EnjoySockets implements a hybrid encryption stack to ensure data confidentiality, integrity, and authenticity. It combines RSA (identity/handshake), ECDH (key exchange), and AES-256-GCM (transport encryption).


Full Documentation & Examples: Visit the GitHub Repository for advanced usage, RPC details, and contribution guidelines.


Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 88 3/3/2026
1.0.0 96 2/27/2026