LiteNetwork.Extensions 2.4.2

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

// Install LiteNetwork.Extensions as a Cake Tool
#tool nuget:?package=LiteNetwork.Extensions&version=2.4.2

LiteNetwork.Extensions

NuGet Version

LiteNetwork is great, this repository aims to make it a little more awesome with some additional features.

Features

  • Simple and easy handling of incoming packets via dependency injection.
  • Added the ability to regsiter a client to an IServiceCollection without registering a hosted service.

Examples

Simple Packet Handling

With LiteNetwork.Extensions you can easily send and receive packets via the packet handling feature. Setup is super simple, the steps are as follows:

  1. Initialize the packet handling feature via ILiteBuilder.UsePacketHandling().
  2. Specify what kind of serialization you want (currently only JSON is provided but you can implement your own via ILitePacketSerializer).
  3. Finally, for each packet you wish to handle register a packet handler via ILiteBuilder.RegisterPacketHandler<TPacket, TPacketHandler>()

Below, you'll find a simple example:

using LiteNetwork.Hosting;
using LiteNetwork.Server.Hosting;
using LiteNetwork.Extensions.Processing.Extensions;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading.Tasks;

var host = new HostBuilder()
    // Configures the LiteNetwork context.
    .ConfigureLiteNetwork((context, builder) =>
    {
        // Add the server or client here...

        builder.UsePacketHandling();
        builder.UseJsonPacketSerialization();
        builder.RegisterPacketHandler<TestPacket, TestPacketHandler>();
    })
    .UseConsoleLifetime()
    .Build();

await host.RunAsync();

And of course, the packet and packet handler classes:

public class TestPacket
{
    public string SomeTestData { get; set; }
}

public class TestPacketHandler : LitePacketHandlerBase<TestPacket>
{
    protected override async Task Handle(TPacket packet, ILitePacketContext context)
    {
        // Run CPU bound if you like.
        await Task.Run(() =>
        {
            Console.WriteLine(packet.SomeTestData);

            // Now let's send a response.
            context.Send(new TestPacket()
            {
                SomeTestData = "LiteNetwork is Awesome!",
            });
        });
    }
}

Build Instructions

Below is a list of prerequisites and build instructions.

Prerequisites

Building on Windows, Mac, and Linux

  1. Download or clone the repository.
  2. Open LiteNetwork.Extensions.sln in your preferred IDE.
  3. Build the solution (or use dotnet build).

Download

  • Release builds will be accessible on GitHub and as NuGet packages.
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
2.4.2 117 1/24/2024
2.4.1 98 1/24/2024

Initial Release