XT.MNet 1.0.7

dotnet add package XT.MNet --version 1.0.7                
NuGet\Install-Package XT.MNet -Version 1.0.7                
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="XT.MNet" Version="1.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XT.MNet --version 1.0.7                
#r "nuget: XT.MNet, 1.0.7"                
#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.
// Install XT.MNet as a Cake Addin
#addin nuget:?package=XT.MNet&version=1.0.7

// Install XT.MNet as a Cake Tool
#tool nuget:?package=XT.MNet&version=1.0.7                

XT.MNet TCP Server/Client

NuGet

Fork From MarvinDrude

Just a small lightweight library for TCP Communication in .NET/C#. It utilizes some techniques from internal kestrel sockets for some performance benefits. Some notes on things used:

Remarks on used technologies

  • Uses some "stackalloc" and "MemoryPool<byte>.Shared" for less heap allocations
  • Usage of "System.IO.Pipelines" for better buffering
  • Custom schedulers for Tasks
  • Custom "PinnedBlockMemoryPool" from kestrel
  • Expression Compilation for better performance of events
  • For Secure Ssl falls back to SslStream under the hood, but still amazingly fast

Simple Usage

You should always first register all the event handlers before calling Server.Start/Client.Connect, in order for you to not miss any instant messages.

Creation of a TCP Server

var server = new TcpServer(new TcpServerOptions() {
    Address = "127.0.0.1", 
    Port = 43434,
    Logger = debugLogger, // ILogger of your liking, default is just console one
    SpecialChar='#' // only work for raw data
  
});
server.Start();
Connect / Disconnect (Connect event is after successful handshake)
server.OnConnect += (connection) => {
    ...
};

server.OnDisconnect += (connection) => {
    ...
};
Register event handler for raw bytes messages
server.On("test-bytes", (buffer, connection) => {

    // important, will only work by using ReadOnlyMemory<byte> here, not byte[], Memory<byte> etc.
    Console.WriteLine("Length: " + buffer.Length);

    // send a raw bytes message (important for sending must be of type Memory<byte>)
    connection.Send("test-bytes", new Memory<byte>([0, 2, 3, 5]));

});
Register Server Raw Data
server.On((buffer, connection) => {

    Console.WriteLine($" {DateTime.Now} Recieve: {Encoding.UTF8.GetString(buffer)} ");


});

Creation of a TCP Client

var client = new TcpClient(new TcpClientOptions() {
    Address = "127.0.0.1",
    Port = 43434,
    Logger = debugLogger, // ILogger of your liking, default is just console one
   
});
client.Connect();
Connect / Disconnect (Connect event is after successful handshake)
client.OnConnect += () => {
    ...
};

client.OnDisconnect += () => {
    ...
};
Register event handler for raw bytes messages
client.On("test-bytes", (buffer) => {

    // important, will only work by using ReadOnlyMemory<byte> here, not byte[], Memory<byte> etc.
    Console.WriteLine("Length: " + buffer.Length);

    // send a raw bytes message (important for sending must be of type Memory<byte>)
    client.Send("test-bytes", new Memory<byte>([0, 2, 3, 5]));

});
Register Raw

client.On(data =>
{
    var str = Encoding.UTF8.GetString(data);
    Console.WriteLine($"{DateTime.Now} {str}");
});
Product Compatible and additional computed target framework versions.
.NET 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. 
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.0.7 73 10/15/2024
1.0.6 127 8/13/2024
1.0.5 70 7/26/2024
1.0.4 107 7/8/2024
1.0.3 113 6/17/2024
1.0.2 104 5/21/2024
1.0.1 112 5/20/2024