{"id":37046220,"url":"https://github.com/vadrsa/simpler","last_synced_at":"2026-01-14T05:28:16.768Z","repository":{"id":39516523,"uuid":"506986482","full_name":"vadrsa/SimpleR","owner":"vadrsa","description":"High Performance Pure WebSocket Server Library based on SignalR","archived":false,"fork":false,"pushed_at":"2025-05-12T10:00:38.000Z","size":114,"stargazers_count":32,"open_issues_count":3,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-11-10T00:43:59.896Z","etag":null,"topics":["csharp","custom","dotnet","signalr","websocket"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vadrsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-06-24T11:32:38.000Z","updated_at":"2025-10-03T11:01:23.000Z","dependencies_parsed_at":"2024-11-01T13:28:01.174Z","dependency_job_id":"9902e90a-504b-443e-be2c-ee4ef14866fd","html_url":"https://github.com/vadrsa/SimpleR","commit_stats":{"total_commits":3,"total_committers":2,"mean_commits":1.5,"dds":"0.33333333333333337","last_synced_commit":"66d08b37b1e296d633a8fb37e1706ff38d015cba"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/vadrsa/SimpleR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadrsa%2FSimpleR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadrsa%2FSimpleR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadrsa%2FSimpleR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadrsa%2FSimpleR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vadrsa","download_url":"https://codeload.github.com/vadrsa/SimpleR/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vadrsa%2FSimpleR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28410415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","custom","dotnet","signalr","websocket"],"created_at":"2026-01-14T05:28:16.039Z","updated_at":"2026-01-14T05:28:16.758Z","avatar_url":"https://github.com/vadrsa.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!----------------------------------- Heading Section ------------------------------------\u003e\n\u003cp align=\"center\"\u003e\n\n![GitHub Cover](https://repository-images.githubusercontent.com/506986482/2795e4c7-8f81-466d-b52c-0abd42c7894e)\n\n\u003c/p\u003e\n\n# SimpleR [![NuGet Version](https://img.shields.io/nuget/v/SimpleR.Server)](https://www.nuget.org/packages/SimpleR.Server)\nSimpleR is a streamlined version of [SignalR](https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/README.md), a high-performance, opinionated, real-time web framework. By removing all the custom protocols from SignalR, we are left with a simpler library, hence the name SimpleR.\n\n# When should I use SimpleR?\nIn short, If you can use SignalR, you should. If not, go with SimpleR.\n\nSimpleR was created to address the need for an easy-to-use, high-performance WebSocket server on .NET, particularly in scenarios where the client cannot use SignalR. For instance, when the client is an IoT device operating with a specific protocol standard over which you have no control ([OCPP](https://openchargealliance.org) for example), SignalR may not be an option. In such cases, you're often left with very low-level programming APIs. SimpleR aims to solve this problem by providing simpler and more familiar APIs to expedite your high-performance WebSocket server development.\n\n# Standard Protocols\n- OCPP [![NuGet Version](https://img.shields.io/nuget/v/SimpleR.Ocpp)](https://www.nuget.org/packages/SimpleR.Ocpp)\n\n# Examples\nExamples can be found [here](https://github.com/vadrsa/SimpleR/tree/master/examples)\n\n# Getting Started\nSimpleR can be installed using the Nuget package manager or the `dotnet` CLI.\n\n```\ndotnet add package SimpleR.Server --prerelease\n```\n\n## Configure SimpleR\nHere is a simple configuration example.\n```cs\nvar builder = WebApplication.CreateBuilder(args);\n\nbuilder.Services.AddSimpleR();\n\nvar app = builder.Build();\n\napp.MapGet(\"/\", () =\u003e \"Hello World!\");\n\napp.MapSimpleR\u003cThermostatMetric, ThermostatCommand\u003e(\"thermostat/{deviceId}\", b =\u003e\n{\n    b.UseDispatcher\u003cThermostatMessageDispatcher\u003e()\n        .UseEndOfMessageDelimitedProtocol(new ThermostatMessageProtocol());\n})\n.RequireAuthorization();\n\napp.Run();\n```\nThe preceding code adds SimpleR to the ASP.NET Core dependency injections, routing systems and defines the message protocol and the message dispatcher.\n## Create a Message Dispatcher\nA message dispatcher is a high-level pipeline that encapsulates the logic of where to dispatch connection messages.\n```cs\npublic class ThermostatMessageDispatcher : IWebSocketMessageDispatcher\u003cThermostatMetric, ThermostatCommand\u003e\n{\n    \n    /// \u003csummary\u003e\n    /// Called when a connection is established.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"connection\"\u003eThe connection.\u003c/param\u003e\n    public Task OnConnectedAsync(IWebsocketConnectionContext\u003cThermostatCommand\u003e connection)\n    {\n        return Task.CompletedTask;\n    }\n\n    /// \u003csummary\u003e\n    /// Called when a connection is disconnected.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"connection\"\u003eThe connection.\u003c/param\u003e\n    /// \u003cparam name=\"exception\"\u003eThe exception that occurred, if any.\u003c/param\u003e\n    public Task OnDisconnectedAsync(IWebsocketConnectionContext\u003cThermostatCommand\u003e connection, Exception? exception)\n    {\n        return Task.CompletedTask;\n    }\n\n    /// \u003csummary\u003e\n    /// Dispatches a message to the application.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"connection\"\u003eThe connection.\u003c/param\u003e\n    /// \u003cparam name=\"message\"\u003eThe message to dispatch.\u003c/param\u003e\n    public async Task DispatchMessageAsync(IWebsocketConnectionContext\u003cThermostatCommand\u003e connection, ThermostatMetric message)\n    {\n        var deviceId = connection.User.FindFirstValue(ClaimTypes.Name) ?? throw new InvalidOperationException(\"Current user is not a device\");\n        var settings = GetSettings(deviceId);\n        if(message is ThermostatTemperatureMetric temperatureMetric)\n        {\n            if (temperatureMetric.Temperature \u003c settings.TargetTemperature)\n            {\n                // If the temperature is below the target temperature, set the thermostat to heat mode\n                await connection.WriteAsync(new SetThermostatModeCommand(ThermostatMode.Heat));\n            }\n            else if (temperatureMetric.Temperature \u003e settings.TargetTemperature)\n            {\n                // If the temperature is above the target temperature, set the thermostat to cool mode\n                await connection.WriteAsync(new SetThermostatModeCommand(ThermostatMode.Cool));\n            }\n            else\n            {\n                // If the temperature is at the target temperature, turn off the thermostat\n                await connection.WriteAsync(new SetThermostatModeCommand(ThermostatMode.Off));\n            }\n        }\n    }\n}\n```\nEach SimpleR route has one message dispatcher instance.\n## Defining Message Protocols\nSince SimpleR is protocol-agnostic, it requires the user to provide a protocol definition to be able to construct a message from the stream of bytes each connection receives.\nThere are two categories of a message protocol:\n- Messages are delimited by the [EndOfMessage flag of WebsocketReceiveResult](https://learn.microsoft.com/en-Us/dotnet/api/system.net.websockets.websocketreceiveresult)\n- Messages have custom delimiters\n### EndOfMessage Delimited Protocol\nHere is a simple delimited protocol implementation:\n```cs\npublic class ThermostatMessageProtocol: IDelimitedMessageProtocol\u003cThermostatMetric, ThermostatCommand\u003e\n{\n    public ThermostatMetric ParseMessage(ref ReadOnlySequence\u003cbyte\u003e input)\n    {\n        var jsonReader = new Utf8JsonReader(input);\n\n        return JsonSerializer.Deserialize\u003cThermostatMetric\u003e(ref jsonReader)!;\n    }\n    \n    public void WriteMessage(ThermostatCommand message, IBufferWriter\u003cbyte\u003e output)\n    {\n        var jsonWriter = new Utf8JsonWriter(output);\n        JsonSerializer.Serialize(jsonWriter, message);\n    }\n}\n```\nTo use the delimited protocol call the `UseEndOfMessageDelimitedProtocol` method of the builder.\n```cs\napp.MapSimpleR\u003cThermostatMetric, ThermostatCommand\u003e(\"thermostat/{deviceId}\", b =\u003e\n{\n    b.UseDispatcher\u003cThermostatMessageDispatcher\u003e()\n        .UseEndOfMessageDelimitedProtocol(new ThermostatMessageProtocol());\n})\n```\n### Custom Protocol\nHere is a simple custom protocol implementation:\n```cs\npublic class ChatMessageProtocol : IMessageProtocol\u003cChatMessage\u003e\n{\n\n    public void WriteMessage(ChatMessage message, IBufferWriter\u003cbyte\u003e output)\n    {\n        var span = output.GetSpan(Encoding.UTF8.GetByteCount(message.Content));\n\n        var bytesWritten = Encoding.UTF8.GetBytes(message.Content, span);\n\n        output.Advance(bytesWritten);\n    }\n\n    public bool TryParseMessage(ref ReadOnlySequence\u003cbyte\u003e input, out ChatMessage message)\n    {\n        var reader = new SequenceReader\u003cbyte\u003e(input);\n\n        if (reader.TryReadTo(out ReadOnlySequence\u003cbyte\u003e payload, delimiter: 0, advancePastDelimiter: true))\n        {\n            message = new ChatMessage { Content = Encoding.UTF8.GetString(payload) };\n            input = reader.UnreadSequence;\n            return true;\n        }\n\n        message = default;\n        return false;\n    }\n}\n```\nTo use the delimited protocol call the `UseCustomProtocol` method of the builder.\n```cs\napp.MapSimpleR\u003cChatMessage\u003e(\"/chat\",\n    b =\u003e\n    {\n        b.UseCustomProtocol(new ChatMessageProtocol())\n        .UseDispatcher\u003cChatMessageDispatcher\u003e();\n    }\n);\n```\n### How to work with low level network buffers\nTo learn more about working with `ReadOnlySequence\u003cT\u003e` and `IBufferWriter\u003cT\u003e` check out [this article](https://learn.microsoft.com/en-us/dotnet/standard/io/buffers).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvadrsa%2Fsimpler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvadrsa%2Fsimpler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvadrsa%2Fsimpler/lists"}