Baubit.Networking 2025.45.2

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

Baubit.Networking

CircleCI codecov NuGet

A .NET 9 networking library providing utilities for TCP communication and testing.

Features

  • TCPLoopback: A utility class that creates a loopback TCP connection with separate client and server streams for testing and inter-process communication.

Installation

Install the NuGet package:

dotnet add package Baubit.Networking

Quick Start

Creating a TCP Loopback Connection

using Baubit.Networking;

// Create a new loopback connection
using var loopback = await TCPLoopback.CreateNewAsync();

// Get the client and server streams
var clientStream = loopback.ClientSideStream;
var serverStream = loopback.ServerSideStream;

Client to Server Communication

using var loopback = await TCPLoopback.CreateNewAsync();

// Client sends a message
var message = "Hello, Server!";
var buffer = Encoding.UTF8.GetBytes(message);
await loopback.ClientSideStream.WriteAsync(buffer);
loopback.ClientSideStream.Flush();

// Server receives the message
var readBuffer = new byte[buffer.Length];
int bytesRead = await loopback.ServerSideStream.ReadAsync(readBuffer, 0, readBuffer.Length);
string receivedMessage = Encoding.UTF8.GetString(readBuffer, 0, bytesRead);

Server to Client Communication

using var loopback = await TCPLoopback.CreateNewAsync();

// Server sends a message
var message = "Hello, Client!";
var buffer = Encoding.UTF8.GetBytes(message);
await loopback.ServerSideStream.WriteAsync(buffer);
loopback.ServerSideStream.Flush();

// Client receives the message
var readBuffer = new byte[buffer.Length];
int bytesRead = await loopback.ClientSideStream.ReadAsync(readBuffer, 0, readBuffer.Length);
string receivedMessage = Encoding.UTF8.GetString(readBuffer, 0, bytesRead);

API Reference

TCPLoopback

A loopback TCP connection that simulates both client and server sides for testing purposes.

Properties
  • ClientSideStream (Stream) - The stream representing the client side of the TCP loopback connection. Supports reading and writing.
  • ServerSideStream (Stream) - The stream representing the server side of the TCP loopback connection. Supports reading and writing.
Methods
  • CreateNewAsync(CancellationToken cancellationToken = default) - static async Task<TCPLoopback>

    Asynchronously creates a new TCP loopback instance with connected client and server streams.

    Parameters:

    • cancellationToken - A cancellation token to cancel the operation (optional).

    Returns: A task that represents the asynchronous operation. The task result contains the created TCPLoopback instance.

IDisposable

TCPLoopback implements IDisposable. Always dispose of the instance when done to properly close the underlying streams.

using var loopback = await TCPLoopback.CreateNewAsync();
// Use loopback...
// Automatically disposed here

Use Cases

  • Unit Testing: Test network communication without actual network calls
  • Inter-process Communication: Mock TCP communication between processes
  • Protocol Testing: Test protocol implementations with guaranteed delivery
  • Network Simulation: Simulate client-server interactions in controlled environments

Testing

Run the test suite:

dotnet test

Tests include:

  • Connection creation and stream validation
  • Client-to-server communication
  • Server-to-client communication
  • Resource disposal and cleanup

Requirements

  • .NET 9 or later

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

For bug reports and feature requests, visit the GitHub repository.


Copyright (c) Prashant Nagoorkar. See LICENSE for details.

Product Compatible and additional computed target framework versions.
.NET 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.  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.
  • 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
2025.45.2 192 11/5/2025