CodeWF.NetWeaver 2.1.1

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

CodeWF.NetWeaver

NuGet NuGet License

CodeWF.NetWeaver is the serialization core for network packets.

CodeWF.NetWrapper builds on top of it and provides TCP/UDP helper classes, command dispatching, and file transfer / file management capabilities.

Chinese version: README.zh-CN.md

Projects

Project Description
CodeWF.NetWeaver Core packet serialization and deserialization library.
CodeWF.NetWrapper TCP/UDP socket helper library built on top of CodeWF.NetWeaver.
SocketTest.Client Demo client for wrapper features.
SocketTest.Server Demo server for wrapper features.

Install

NuGet\Install-Package CodeWF.NetWeaver

Repository Baseline

  • Development SDK: .NET 11 preview, pinned through global.json
  • Package management: centralized with Directory.Packages.props
  • Core libraries: CodeWF.NetWeaver and CodeWF.NetWrapper
  • Sample UI stack: Avalonia 12.0.2, Semi.Avalonia 12.0.1, ReactiveUI.Avalonia 12.0.1
  • Free-only policy: Prism.DryIoc.Avalonia remains pinned to 8.1.97.11073
  • Grid migration: the sample applications now use CodeWF.AvaloniaControls.ProDataGrid instead of the old free Avalonia.Controls.DataGrid line

Build And Scripts

Restore, build, and test the whole solution:

dotnet restore CodeWF.NetWeaver.slnx
dotnet build CodeWF.NetWeaver.slnx -c Debug
dotnet test CodeWF.NetWeaver.slnx -c Debug --no-build

Pack the NuGet libraries:

pack.bat

Publish the runnable samples:

publish_all.bat

Packet Model

Each packet contains a fixed header plus the serialized object body:

Header
- BufferLen: int
- SystemId: long
- ObjectId: ushort
- ObjectVersion: byte
- UnixTimeMilliseconds: long

Body
- Serialized object payload

Mark a DTO with NetHead so the serializer can identify it on the wire:

using CodeWF.NetWeaver.Base;

[NetHead(10, 1)]
public class ResponseProcessList : INetObject
{
    public int TaskId { get; set; }

    public int TotalSize { get; set; }

    public List<ProcessItem>? Processes { get; set; }
}

public record ProcessItem
{
    public int Pid { get; set; }

    public string? Name { get; set; }
}

Basic Usage

Serialize:

var netObject = new ResponseProcessList
{
    TaskId = 3,
    TotalSize = 2,
    Processes =
    [
        new ProcessItem { Pid = 1, Name = "CodeWF.NetWeaver" },
        new ProcessItem { Pid = 2, Name = "CodeWF.NetWrapper" }
    ]
};

var buffer = netObject.Serialize(systemId: 32);

Deserialize:

var deserialized = buffer.Deserialize<ResponseProcessList>();

Console.WriteLine(deserialized.TotalSize);

CodeWF.NetWrapper

CodeWF.NetWrapper handles TCP/UDP communication and converts raw packets into typed commands:

using CodeWF.EventBus;
using CodeWF.NetWrapper.Commands;
using CodeWF.NetWrapper.Helpers;

var server = new TcpSocketServer();
await server.StartAsync("Server", "0.0.0.0", 8888);

EventBus.Default.Subscribe<SocketCommand>(async (sender, command) =>
{
    // Non-file-management commands can be processed here.
});

File Transfer And File Management

TcpSocketClient and TcpSocketServer now expose a clearer file management API:

Every request/response-style communication object carries a TaskId. The same TaskId is propagated through request, response, chunk data, chunk acknowledgement, reject, and complete messages so callers can correlate a full transfer flow reliably.

Client API

await client.BrowseFileSystemAsync("/");
await client.CreateDirectoryAsync("uploads");
await client.DeletePathAsync("old-folder", true);
await client.DeletePathAsync("uploads/old.bin", false);
await client.UploadFileAsync(@"D:\local\demo.zip", "uploads/demo.zip");
await client.DownloadFileAsync("uploads/demo.zip", @"D:\downloads");

Server Configuration

var server = new TcpSocketServer
{
    // All browse/create/delete/upload/download operations are restricted to this root.
    FileSaveDirectory = @"D:\ServerFiles"
};

server.FileTransferProgress += (sender, args) =>
{
    Console.WriteLine($"{args.FileName}: {args.Progress:F2}%");
};

Managed Root Behavior

When FileSaveDirectory is set:

  • Browsing, creating, deleting, uploading, and downloading are restricted to that root directory.
  • Relative paths such as "uploads/demo.zip" are resolved under the managed root.
  • Attempts to escape the root with paths like "..\\outside.txt" are rejected by the server.

Transfer Behavior

  • Transfers use 64 KB blocks.
  • Upload and download both support resume by offset.
  • Completed files are verified with SHA-256.
  • FileTransferProgress is raised on both client and server sides.

File Management DTOs

The file management feature now uses the cleaned-up names below:

Category Type
Browse request BrowseFileSystemRequest
Browse response BrowseFileSystemResponse
Drive list response DriveListResponse
Create directory request CreateDirectoryRequest
Create directory response CreateDirectoryResponse
Delete path request DeletePathRequest
Delete path response DeletePathResponse

File Transfer DTOs

The file transfer pipeline now uses these names:

Category Type
Upload request FileUploadRequest
Upload response FileUploadResponse
Download request FileDownloadRequest
Download response FileDownloadResponse
Chunk data FileChunkData
Chunk acknowledgement FileChunkAck
Transfer reject FileTransferReject
Transfer complete FileTransferComplete

Tests

The repository includes integration-style tests for the wrapper file pipeline:

  • upload into the managed server root
  • download into the requested local directory
  • reject path traversal outside FileSaveDirectory

Run them with:

dotnet test src\CodeWF.NetWrapper.Tests\CodeWF.NetWrapper.Tests.csproj

Design Notes

The design note document is available here:

CodeWF-NetWeaver-Design-Principles.md

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CodeWF.NetWeaver:

Package Downloads
CodeWF.NetWrapper

CodeWF.NetWrapper builds on CodeWF.NetWeaver and provides TCP/UDP helpers, command dispatching, and file transfer or file management capabilities.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.1 101 5/3/2026
2.1.0 120 4/17/2026
2.0.24 149 2/13/2026
2.0.23 140 1/23/2026
2.0.20 139 1/5/2026
2.0.14 214 12/25/2025
2.0.7 200 12/14/2025
2.0.6 204 12/13/2025
2.0.3 485 12/10/2025
2.0.2 467 12/10/2025
2.0.1 461 12/10/2025
2.0.0.1 259 11/4/2025
2.0.0 259 9/5/2025
1.3.1 279 5/8/2025
1.3.0 895 9/21/2024
1.2.1 182 9/19/2024
1.2.0 220 9/19/2024
1.1.1.1 208 9/13/2024
1.1.1 207 7/27/2024
1.1.0 211 7/9/2024
Loading failed