Orion.Network.Core 0.8.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Orion.Network.Core --version 0.8.0
                    
NuGet\Install-Package Orion.Network.Core -Version 0.8.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="Orion.Network.Core" Version="0.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Orion.Network.Core" Version="0.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Orion.Network.Core" />
                    
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 Orion.Network.Core --version 0.8.0
                    
#r "nuget: Orion.Network.Core, 0.8.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.
#addin nuget:?package=Orion.Network.Core&version=0.8.0
                    
Install Orion.Network.Core as a Cake Addin
#tool nuget:?package=Orion.Network.Core&version=0.8.0
                    
Install Orion.Network.Core as a Cake Tool

Orion.Network.Core

NuGet Version License .NET

Networking abstractions for the Orion IRC Server project.

IRC is not dead, long live IRC!

About

Orion.Network.Core provides the foundational networking abstraction layer for Orion IRC Server. This library offers a transport-agnostic approach to network communication, allowing the IRC server to work with different transport mechanisms (TCP, WebSockets, etc.) through a unified interface.

Installation

dotnet add package Orion.Network.Core

Or using the Package Manager Console:

Install-Package Orion.Network.Core

Key Features

  • Transport Abstraction: Interface-based design for network transports
  • Message Handling: Unified message reception and dispatch
  • Connection Management: Client connection tracking and lifecycle
  • Reactive Design: Event-based communication using System.Reactive
  • Protocol-Independent: Works with various network protocols
  • Network Data Types: Strong typing for network messages and structures
  • Message Parsers: Tools for parsing and processing network messages

Transport System

Orion.Network.Core defines a transport system through the INetworkTransport interface, allowing different implementations to provide network connectivity:

public interface INetworkTransport
{
    event ClientConnectedHandler ClientConnected;
    event ClientDisconnectedHandler ClientDisconnected;
    event MessageReceivedHandler MessageReceived;

    string Id { get; }
    string Name { get; }
    NetworkProtocolType Protocol { get; }
    NetworkSecurityType Security { get; }
    ServerNetworkType ServerNetworkType { get; }
    string IpAddress { get; }
    int Port { get; }

    Task StartAsync();
    Task StopAsync();
    Task SendAsync(string sessionId, byte[] message, CancellationToken cancellationToken = default);
    bool HaveSession(string sessionId);
}

Examples

Working with the Transport Manager

using Orion.Network.Core.Interfaces.Services;
using Orion.Network.Core.Data;
using System.Text;

public class NetworkExample
{
    private readonly INetworkTransportManager _transportManager;

    public NetworkExample(INetworkTransportManager transportManager)
    {
        _transportManager = transportManager;

        // Subscribe to incoming messages
        _transportManager.IncomingMessages.Subscribe(HandleIncomingMessage);

        // Handle connection events
        _transportManager.ClientConnected += OnClientConnected;
        _transportManager.ClientDisconnected += OnClientDisconnected;
    }

    private void OnClientConnected(string transportId, string sessionId, string endpoint)
    {
        Console.WriteLine($"Client connected: {sessionId} from {endpoint} via {transportId}");
    }

    private void OnClientDisconnected(string transportId, string sessionId, string endpoint)
    {
        Console.WriteLine($"Client disconnected: {sessionId} from {endpoint} via {transportId}");
    }

    private async Task HandleIncomingMessage(NetworkMessageData message)
    {
        Console.WriteLine($"Message from {message.SessionId}: {message.Message}");

        // Send a response
        await _transportManager.EnqueueMessageAsync(
            new NetworkMessageData(message.SessionId, "Echo: " + message.Message, message.ServerNetworkType)
        );
    }
}

Implementing a Custom Transport

using Orion.Core.Types;
using Orion.Network.Core.Interfaces.Transports;
using Orion.Network.Core.Types;

public class MyCustomTransport : INetworkTransport
{
    public event INetworkTransport.ClientConnectedHandler ClientConnected;
    public event INetworkTransport.ClientDisconnectedHandler ClientDisconnected;
    public event INetworkTransport.MessageReceivedHandler MessageReceived;

    public string Id { get; } = Guid.NewGuid().ToString();
    public string Name { get; } = "MyCustomTransport";
    public NetworkProtocolType Protocol => NetworkProtocolType.Custom;
    public NetworkSecurityType Security => NetworkSecurityType.None;
    public ServerNetworkType ServerNetworkType { get; }
    public string IpAddress { get; }
    public int Port { get; }

    private readonly Dictionary<string, MyClient> _clients = new();

    public MyCustomTransport(ServerNetworkType serverNetworkType, string ipAddress, int port)
    {
        ServerNetworkType = serverNetworkType;
        IpAddress = ipAddress;
        Port = port;
    }

    public Task StartAsync()
    {
        // Initialize transport
        return Task.CompletedTask;
    }

    public Task StopAsync()
    {
        // Shutdown transport
        return Task.CompletedTask;
    }

    public Task SendAsync(string sessionId, byte[] message, CancellationToken cancellationToken = default)
    {
        if (_clients.TryGetValue(sessionId, out var client))
        {
            return client.SendAsync(message);
        }

        throw new InvalidOperationException($"Session {sessionId} not found.");
    }

    public bool HaveSession(string sessionId)
    {
        return _clients.ContainsKey(sessionId);
    }

    // Helper class for the example
    private class MyClient
    {
        public Task SendAsync(byte[] message) => Task.CompletedTask;
    }
}

Using the Message Parser

using Orion.Network.Core.Parsers;

// Parse messages from byte buffer
byte[] buffer = Encoding.UTF8.GetBytes("NICK user1\r\nUSER user1 0 * :Real Name\r\n");
var messages = NewLineMessageParser.ParseMessages(buffer);

foreach (var message in messages)
{
    Console.WriteLine($"Parsed message: {message}");
}

Dependencies

  • Orion.Core: Core utilities and extensions
  • Orion.Irc.Core: IRC protocol implementation
  • System.Reactive: Reactive programming support
  • Microsoft.Extensions.Logging.Abstractions: Logging infrastructure
  • Orion.Network.Tcp: TCP implementation for network transports
  • Orion.Core.Server: Server-side core functionality

License

This project is licensed under the MIT License - see the LICENSE file 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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Orion.Network.Core:

Package Downloads
Orion.Network.Tcp

TCP implementation for Orion IRC Server networking

Orion.Core.Server

Server-side core functionality for Orion IRC Server

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.30.1 169 5/15/2025
0.30.0 175 5/13/2025
0.29.0 211 5/12/2025
0.28.4 192 5/12/2025
0.28.3 188 5/12/2025
0.28.2 206 5/12/2025
0.28.1 127 5/11/2025
0.28.0 61 5/10/2025
0.27.1 167 5/8/2025
0.27.0 135 5/8/2025
0.26.0 132 5/8/2025
0.25.2 133 5/8/2025
0.25.1 139 5/8/2025
0.25.0 147 5/8/2025
0.24.0 140 5/6/2025
0.23.0 138 5/6/2025
0.22.3 136 5/6/2025
0.22.2 140 5/5/2025
0.22.0 99 5/2/2025
0.21.0 100 5/2/2025
0.20.0 107 5/2/2025
0.19.1 114 5/2/2025
0.19.0 138 5/1/2025
0.18.1 135 5/1/2025
0.18.0 142 4/30/2025
0.17.0 139 4/29/2025
0.16.0 166 4/29/2025
0.15.0 152 4/28/2025
0.14.3 153 4/28/2025
0.14.2 154 4/28/2025
0.14.1 148 4/28/2025
0.14.0 147 4/28/2025
0.13.0 151 4/28/2025
0.12.3 148 4/28/2025
0.12.2 153 4/28/2025
0.12.1 152 4/28/2025
0.12.0 139 4/28/2025
0.11.1 156 4/28/2025
0.11.0 146 4/28/2025
0.10.0 152 4/28/2025
0.9.0 152 4/23/2025
0.8.0 159 4/23/2025
0.7.0 163 4/22/2025
0.6.1 147 4/22/2025
0.6.0 163 4/20/2025
0.5.0 156 4/20/2025
0.4.0 160 4/20/2025
0.3.0 91 4/19/2025
0.2.0 140 4/18/2025
0.1.10 161 4/18/2025
0.1.9 164 4/18/2025
0.1.8 171 4/18/2025
0.1.7 157 4/18/2025
0.1.6 165 4/18/2025
0.1.5 167 4/18/2025
0.1.4 161 4/18/2025
0.1.3 180 4/17/2025
0.1.2 187 4/17/2025