EnjoySockets 1.1.0
dotnet add package EnjoySockets --version 1.1.0
NuGet\Install-Package EnjoySockets -Version 1.1.0
<PackageReference Include="EnjoySockets" Version="1.1.0" />
<PackageVersion Include="EnjoySockets" Version="1.1.0" />
<PackageReference Include="EnjoySockets" />
paket add EnjoySockets --version 1.1.0
#r "nuget: EnjoySockets, 1.1.0"
#:package EnjoySockets@1.1.0
#addin nuget:?package=EnjoySockets&version=1.1.0
#tool nuget:?package=EnjoySockets&version=1.1.0
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
asyncsupport. - Resource Control: Robust flow control using
System.Threading.Channelsand 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 | Versions 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. |
-
net6.0
- MemoryPack (>= 1.21.4)
-
net8.0
- MemoryPack (>= 1.21.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.