XT.MNet 1.0.8

dotnet add package XT.MNet --version 1.0.8
                    
NuGet\Install-Package XT.MNet -Version 1.0.8
                    
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.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XT.MNet" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="XT.MNet" />
                    
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 XT.MNet --version 1.0.8
                    
#r "nuget: XT.MNet, 1.0.8"
                    
#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 XT.MNet@1.0.8
                    
#: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=XT.MNet&version=1.0.8
                    
Install as a Cake Addin
#tool nuget:?package=XT.MNet&version=1.0.8
                    
Install as a Cake Tool

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.  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 (1)

Showing the top 1 NuGet packages that depend on XT.MNet:

Package Downloads
Audio.Core

音频核心库

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.8 155 6/17/2025
1.0.7 125 10/15/2024
1.0.6 156 8/13/2024
1.0.5 98 7/26/2024
1.0.4 136 7/8/2024
1.0.3 139 6/17/2024
1.0.2 134 5/21/2024
1.0.1 142 5/20/2024