EnjoySockets 1.3.0
See the version list below for details.
dotnet add package EnjoySockets --version 1.3.0
NuGet\Install-Package EnjoySockets -Version 1.3.0
<PackageReference Include="EnjoySockets" Version="1.3.0" />
<PackageVersion Include="EnjoySockets" Version="1.3.0" />
<PackageReference Include="EnjoySockets" />
paket add EnjoySockets --version 1.3.0
#r "nuget: EnjoySockets, 1.3.0"
#:package EnjoySockets@1.3.0
#addin nuget:?package=EnjoySockets&version=1.3.0
#tool nuget:?package=EnjoySockets&version=1.3.0
EnjoySockets
EnjoySockets is a lightweight, low-latency, message-driven TCP runtime for C# with RPC routing, actor-like instances and deterministic execution channels.
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 uses MemoryPack as the default serializer for high-performance binary serialization.
You can also provide your own binary serializer implementation (for example MessagePack or Protocol Buffers) through the ESerial property in ETCPConfig.
To implement a custom serializer, create a class that implements the IESerializer interface and assign an instance of that class to the configuration.
When using the default MemoryPack serializer, 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" />
</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.
string pemKeyPrivate = "-----BEGIN PRIVATE KEY-----<your_pem_key>-----END PRIVATE KEY-----";
string pemKeyPrivateSign = "-----BEGIN PRIVATE KEY-----<your_pem_key>-----END PRIVATE KEY-----";
var server = new ETCPServer(new(pemKeyPrivate, pemKeyPrivateSign));
server.Start(EAddress.Get());
Console.ReadKey();
static class ExampleReceiveClassServer
{
static void TestMethod(EUserServer user)
{
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-----<your_pem_key>-----END PUBLIC KEY-----";
string pemKeyPublicSign = "-----BEGIN PUBLIC KEY-----<your_pem_key>-----END PUBLIC KEY-----";
var client = new EUserClient(new(pemKeyPublic, pemKeyPublicSign));
if(await client.Connect(EAddress.Get()) == 0)
await client.Send("TestMethod");
Console.ReadKey();
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.