Sanet.Transport.SignalR 0.4.1

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

Sanet.Transport.SignalR

ASP.NET Core SignalR implementation of the Sanet.Transport abstractions for real-time communication over networks.

NuGet

Overview

Sanet.Transport.SignalR provides an implementation of the ITransportPublisher interface using ASP.NET Core SignalR, enabling real-time communication between applications over a network. The library encapsulates all SignalR infrastructure, keeping client applications clean from web server dependencies.

Features

  • Real-time communication between applications over a network
  • Client-server architecture with separate client and server publishers
  • Automatic host discovery on simple local networks
  • Self-contained SignalR infrastructure (no need to add ASP.NET Core to client apps)

Installation

dotnet add package Sanet.Transport.SignalR

Or via the Package Manager Console:

Install-Package Sanet.Transport.SignalR

Usage

Server-side (Host)

// Create a SignalR host (server)
var hostManager = await SignalRTransportFactory.CreateHostAsync(port: 5000);

// Get the server-side publisher
ITransportPublisher serverPublisher = hostManager.Publisher;

// Subscribe to messages from clients
serverPublisher.Subscribe(message => {
    Console.WriteLine($"Server received: {message.CommandType}");
    
    // Broadcast a response to all clients
    serverPublisher.PublishMessage(new TransportMessage {
        CommandType = "ServerResponse",
        SourceId = Guid.NewGuid(),
        Payload = "{\"server\": \"response\"}",
        Timestamp = DateTime.UtcNow
    });
});

Client-side

// Discover hosts on the network
var hosts = await discoveryService.DiscoverHostsAsync(timeoutSeconds: 5);

// Connect to the first discovered host
if (hosts.Count > 0)
{
    // Create a client publisher connected to the host
    ITransportPublisher clientPublisher = SignalRTransportFactory.CreateClient(hosts[0]);
    
    // Subscribe to messages from the server
    clientPublisher.Subscribe(message => {
        Console.WriteLine($"Client received: {message.CommandType}");
    });
    
    // Send a message to the server
    clientPublisher.PublishMessage(new TransportMessage {
        CommandType = "ClientCommand",
        SourceId = Guid.NewGuid(),
        Payload = "{\"client\": \"data\"}",
        Timestamp = DateTime.UtcNow
    });
}

Manual Connection (Without Discovery)

// Connect to a known host
var hostInfo = new HostInfo { Url = "http://192.168.1.100:5000" };
ITransportPublisher clientPublisher = SignalRTransportFactory.CreateClient(hostInfo);

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.