Akka.IO.TcpTools 1.0.1

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

// Install Akka.IO.TcpTools as a Cake Tool
#tool nuget:?package=Akka.IO.TcpTools&version=1.0.1                

Akka.IO.TcpTools

This package is created in order to make WebSocket message receiving / sending easier in the Akka ActorSystem.

The WebSocketConnectionActorBase class can be used as a WebSocketClient. It decodes received messages, can receive framed messages and have the possibility to response to Ping/Pong messages if the OnPingReceivedAsync / OnPongReceivedAsync methods ovewritten.

Example for basic usage:

using Akka.Actor;
using Akka.DependencyInjection;
using Akka.IO;
using Akka.IO.TcpTools;
using Akka.IO.TcpTools.Actor;
using Microsoft.Extensions.Logging;
using System.Net;

namespace BasicWebSocketConnection
{
    public class BasicWebSocketConnectionManagerActor : ReceiveActor
    {
        private ILogger<BasicWebSocketConnectionManagerActor> _logger;

        public BasicWebSocketConnectionManagerActor(ILogger<BasicWebSocketConnectionManagerActor> logger, int port)
        {
            _logger = logger;

            Context.System
                .Tcp()
                .Tell(new Tcp.Bind(Self, new IPEndPoint(IPAddress.Any, port), options: new[] { new Inet.SO.ReceiveBufferSize(1024) }));

            Receive<Tcp.Bound>(OnBound);
            Receive<Tcp.Connected>(OnConnected);
        }

        protected virtual void OnBound(Tcp.Bound bound)
        {
            _logger.LogInformation("{ActorName} Listening on {LocalAddress}", nameof(BasicWebSocketConnectionManagerActor), bound.LocalAddress);
        }

        protected virtual void OnConnected(Tcp.Connected connected)
        {
            _logger.LogInformation("{ActorName} received a connection from {RemoteAddress}", nameof(BasicWebSocketConnectionManagerActor), connected.RemoteAddress);

            var actorProps = DependencyResolver
                .For(Context.System)
                .Props<BasicWebSocketConnectionActor>();

            var name = $"basicwebsocketconnection_{connected.RemoteAddress}_{Guid.NewGuid():N}";
            var basicWebSocketConnectionActor = Context.ActorOf(actorProps, name);

            _logger.LogInformation("BasicWebSocketConnectionActor created with name: {name}", name);

            Sender.Tell(new Tcp.Register(basicWebSocketConnectionActor));
        }
    }

    public class BasicWebSocketConnectionActor : WebSocketConnectionActorBase
    {
        public BasicWebSocketConnectionActor(ILogger<BasicWebSocketConnectionActor> logger) : base(logger)
        { }

        protected override async Task OnStringReceivedAsync(string message)
        {
            Logger.LogInformation("Got a string message: {message}", message);

            var payload = await ByteStringWriter.WriteAsTextAsync($"Thanks for your message: {message}");
            Sender.Tell(Tcp.Write.Create(payload));
        }
    }
}
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
1.0.1 394 11/30/2023
0.0.3 277 4/21/2023
0.0.2 413 12/1/2022
0.0.1 352 12/1/2022