Jbi.TcpLib 2.1.0

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

// Install Jbi.TcpLib as a Cake Tool
#tool nuget:?package=Jbi.TcpLib&version=2.1.0                

Jbi.Tcp

This library provides easy to use TcpClient and TcpServer. It reduces the hustle to manage the tcp stuff yourself. Caution! As tcp data comes in as streams of data. We will not Buffer the data, as the user is responsible for that as we do not know how the messages will look like. So we are just passing over the raw memory chunks.

Client samples

Create a client

Create and connect a client

using System.Net;
using Jbi.TcpLib;

using CancellationTokenSource cts = new ();
using TcpClient client = new (new IPEndPoint(IPAddress.Loopback, 53467));

await client.ConnectAsync(cts.Token);

client.Disconnect();

Read data

using System.Net;
using Jbi.TcpLib;

...

// Read data
// Await foreach over each received data chunk
await foreach (var pooledMemory in client.ReadDataAsync(1024, cts.Token))
{
	// We do return a PooledMemory<T> here. This is to indicate to you that you have to dispose the memory after use
	try
	{
		// do something with the data either as memory or as span. 
		// Both will contain the same data, the span is provided for a smaller code footprint
		//pooledMemory.Memory;
		//pooledMemory.Span;
	}
	finally
	{
		pooledMemory.Dispose();
	}
} 

Write data

using System.Net;
using Jbi.TcpLib;

...

// Write as string
await client.SendDataAsync("Hello World!");

// Write as memory
var data = "Hello World!"u8.ToArray();
await client.SendDataAsync(data);

Sever samples

Create

using System.Net;
using Jbi.TcpLib;

IPEndPoint endPoint = new (IPAddress.Loopback, 0);
using TcpServerSimple server = new (endPoint);

await server.StartAsync();

await server.StopAsync();

Read data

using System.Net;
using Jbi.TcpLib;

...

// Read data 
await foreach (var pooledMemory in server.ReadAllAsync())
{
	try
	{
		// Do something with that data
		//pooledMemory.Memory;
		//pooledMemory.Span;
	}
	finally
	{
		pooledMemory.Dispose();
	}
}

Write data

using System.Net;
using Jbi.TcpLib;

...

// Write data
await server.SendDataAsync("Hallo Welt");

var data = "Hallo Welt!"u8.ToArray();
await server.SendDataAsync(data);
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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

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
2.1.0 77 2/8/2025
2.0.1 63 2/8/2025
2.0.0 62 2/8/2025
2.0.0-preview3 57 1/14/2025
2.0.0-preview2 60 1/13/2025
2.0.0-preview1 63 1/13/2025
1.0.2-preview1 51 1/10/2025
1.0.1 176 1/16/2024
1.0.0 114 1/13/2024

Initial release