Fomoxa.Rpc 0.1.0

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

frpc-csharp

fRPC for .NET: the RPC layer on top of Fomoxa, written from the fRPC design. Where this code and the design disagree, the design decides and this code changes.

It is the second implementation, after frpc-rust; frpc-go is the third. All three exchange identical bytes, and this test suite checks that against the Rust binary on every run.

Layout

Path Contents
src/Fomoxa.Rpc The pure core: wire format, ctx block, registry, send queues and scheduler, interceptors, credit, compression, retry, reflection. No threads, no clock, no I/O
src/Fomoxa.Rpc/Net The shell over Fomoxa.Net: a socket transport, RpcSession, the wait step, a blocking RpcClient, and a ThreadedServer with one thread per connection
examples/Demo The demo schema (the same 19 models as frpc-rust's demo), the codecs fomoxac generated from it, and the methods both implementations serve
examples/Interop frpc-interop, the C# half of the cross-language test
tests/Fomoxa.Rpc.Tests 99 tests: design §16 on the core, the shell over TCP, and interoperability with frpc-rust

Fomoxa.Rpc targets net8.0 and references the Fomoxa.Net package, version 0.1.0. It needs no change to Fomoxa.Net (design R12).

Using it

A method is identified by the message id of its request model (design §3.3), and ids come from the codec fomoxac generated:

var say = Method.Unary("Echo.Say", EchoRequestRpcCodec.MessageId, EchoResponseRpcCodec.MessageId);

var registry = Registry.Builder(FRpcVoidRpcCodec.MessageId, FRpcErrorRpcCodec.MessageId)
    .Credit(FRpcCreditRpcCodec.MessageId)
    .Serve(say, (_, body) => Immediate.Respond(Shout(body)))
    .Reflection(FRpcReflectRequestRpcCodec.MessageId, FRpcReflectResponseRpcCodec.MessageId, schemaJson)
    .Build();

using var server = ThreadedServer.Bind("127.0.0.1", 9431, schema, registry);
server.Run();
using var client = RpcClient.Connect("127.0.0.1", 9431, schema, callerRegistry, TimeSpan.FromSeconds(5));
var outcome = client.Invoke(EchoRequestRpcCodec.MessageId, body, ctx: null, CallOptions.Within(TimeSpan.FromSeconds(2)));

A handler implements IHandler.Poll(now) and returns Pending, Respond, Item, End or Fail. A stream handler may also accept caller items, hear the end of the caller's stream, and grant credit for the caller direction. A handler or factory refuses a call by throwing StatusException. Any other exception becomes INTERNAL for that call alone and does not reach the session.

The API has three levels, matching the two driving modes of design §19:

Type Who drives it
RpcCore The application, with an injected now. Frames in through OnMessage, frames out through Drain. This is the level every in-memory test uses
RpcSession The application, calling Tick(now) and Wait(policy, now) in its own loop
RpcClient, ThreadedServer The library. RpcClient blocks the calling thread until an outcome arrives; ThreadedServer runs one thread per connection, blocked in the kernel while idle

The wait step

The wait step has to know whether bytes are being held back, to choose between waiting for readable and waiting for readable or writable (design §19). Fomoxa.Net's connection does not report that, so the shell brings its own SocketTransport. Its Backlogged flag is set while bytes from a partial send are still unsent or the last send was refused, and RpcSession.Wait uses it. An idle connection wakes about four times a second, at the 250 ms idle ceiling.

Interoperability

fomoxac 0.2.1 generated both demo schemas, one from Rust attributes and one from C# attributes. All 19 messages agree on id and prefix fingerprints, and the whole-schema fingerprint is 0xB8F0E2543FC9C60D on both sides, so a C# peer and a Rust peer complete the handshake on its first comparison.

frpc-interop and frpc-rust's interop example take the same commands:

Command What it does
serve <host:port> Serves Echo.Say, Echo.Count, Blob.Upload, Room.Chat, Clock.Ticks and FRpc.Reflect, prints listening <address>, runs until stdin closes
drive <host:port> Runs eleven checks against any fRPC server: unary, server stream, client stream, bidi, their error paths, credit, a stream deadline, UNIMPLEMENTED for a type the server does not serve, and reflection
frames Two cores exchange one fixed scenario in memory; prints every frame as hex
frpc-rust$   cargo run --features net --example interop -- serve 127.0.0.1:9521
frpc-csharp$ dotnet run --project examples/Interop -- drive 127.0.0.1:9521

The test suite runs all of it itself: it builds the Rust binary with cargo if it is missing, then checks that

  • the 25 frames of the frames scenario are identical, line for line: a REQUEST with a ctx block, CREDIT placed after its REQUEST, ITEM, END, RESPONSE, ERROR for INVALID_ARGUMENT, UNIMPLEMENTED and CANCELLED, and CANCEL
  • a C# client passes the eleven checks against a Rust server, and a Rust client passes them against a C# server
  • a C# server whose EchoRequest has a field appended serves an older Rust client, and a C# client with the appended field is served by an older Rust server, which asks for the client's prefix fingerprint in the handshake's query round, then reads the fields it knows and ignores the rest (RFC-0002 §9.1)

frpcurl also works against the C# server, since reflection returns the C# schema.json:

$ frpcurl 127.0.0.1:9522 load
loaded 6 methods and 19 models from 127.0.0.1:9522
$ frpcurl 127.0.0.1:9522 call Echo.Say -d '{"Text":"xin chào"}'
{
  "Text": "XIN CHÀO"
}

Field names in the C# schema.json are the C# property names, so the JSON keys frpcurl expects are Text, not text. The wire bytes do not depend on field names.

Building and testing

dotnet build Fomoxa.Rpc.sln
dotnet run --project tests/Fomoxa.Rpc.Tests            # all 99
dotnet run --project tests/Fomoxa.Rpc.Tests -- credit  # groups or names containing "credit"

On a machine without ICU, set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 for the dotnet CLI itself; the test and interop executables already run in invariant mode.

The interoperability group expects ../frpc-rust beside this repository and cargo on the path.

The models are regenerated by hand, from the directory that holds each fomoxa.toml:

cd examples/Demo && fomoxac generate
cd tests/Fomoxa.Rpc.Tests/Skew && fomoxac generate

License

Apache-2.0, see LICENSE.

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.  net9.0 was computed.  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.

Version Downloads Last Updated
0.1.0 151 9/21/2026