PurpleSofa 0.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package PurpleSofa --version 0.0.8
NuGet\Install-Package PurpleSofa -Version 0.0.8
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="PurpleSofa" Version="0.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PurpleSofa --version 0.0.8
#r "nuget: PurpleSofa, 0.0.8"
#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 PurpleSofa as a Cake Addin
#addin nuget:?package=PurpleSofa&version=0.0.8

// Install PurpleSofa as a Cake Tool
#tool nuget:?package=PurpleSofa&version=0.0.8

PurpleSofa - C# .NET async tcp server & client

nuget .NET CI codecov License


  • Callback for 'OnOpen'(accepted or connected), 'OnMessage'(received), 'OnClose'(received none).
  • Can store user value in session.
  • Check timeout at regular intervals by last receive time. It's useful to detect 'half close'.
  • 'OnClose' execution is taken via queue in order to avoid simultaneously many 'close'.

how to use


public class Callback : PsCallback
    private const string Key = "inc";
    public override void OnOpen(PsSession session)
        Console.WriteLine($"OnOpen {session}");
        session.SetValue(Key, 0);

        int inc = session.GetValue<int>(Key);
        session.Send($"inc: {inc}");

    public override void OnMessage(PsSession session, byte[] message)
        Console.WriteLine($"OnMessage {session} {Encoding.UTF8.GetString(message)}");
        int inc = session.GetValue<int>(Key);
        session.SetValue(Key, inc);
        session.Send($"inc: {inc}");
        if (inc > 3) session.Close();

    public override void OnClose(PsSession session, PsCloseReason closeReason)
        int inc = session.GetValue<int>(Key);
        Console.WriteLine($"OnClose {session} {closeReason}, inc:{inc}");

for server

public static void Main(string[] args)
    var server = new PsServer(new Callback());
    // --- another thread
    // server.Shutdown();

for client

public static void Main(string[] args)
    var client = new PsClient(new Callback(), "", 8710);
    // ...
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PurpleSofa:

Package Downloads

Fluent forwarded server.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.0 137 4/15/2024
0.1.1 411 12/8/2023
0.1.0 452 9/5/2023
0.0.9 614 1/3/2023
0.0.8 616 12/20/2022
0.0.7 718 12/12/2022
0.0.6 956 1/24/2022
0.0.5 929 1/13/2022
0.0.4 595 12/21/2021
0.0.3 619 12/10/2021
0.0.2 667 12/2/2021
0.0.1 629 12/2/2021