McComms.gRPC 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package McComms.gRPC --version 1.0.1
                    
NuGet\Install-Package McComms.gRPC -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="McComms.gRPC" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="McComms.gRPC" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="McComms.gRPC" />
                    
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 McComms.gRPC --version 1.0.1
                    
#r "nuget: McComms.gRPC, 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.
#:package McComms.gRPC@1.0.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=McComms.gRPC&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=McComms.gRPC&version=1.0.1
                    
Install as a Cake Tool

McComms.gRPC

gRPC implementation for the McComms solution. This package provides gRPC-based implementations of the ICommsClient and ICommsServer interfaces from McComms.Core.

gRPC Communication Model

gRPC uses Protocol Buffers (protobuf) for efficient serialization and HTTP/2 for transport.

Protocol Structure

The gRPC service is defined in the commands.proto file:

syntax = "proto3";

package commsproto;

service CommandService {
  rpc SendCommand (mcCommandRequest) returns (mcCommandResponse);
  rpc SubscribeToBroadcast (Empty) returns (stream mcBroadcast);
}

message mcCommandRequest {
  int32 id = 1;
  string content = 2;
}

message mcCommandResponse {
  bool success = 1;
  string message = 2;
}

message mcBroadcast {
  int32 id = 1;
  string content = 2;
}

message Empty {}

Command Flow

+--------+                        +--------+
| Client |                        | Server |
+--------+                        +--------+
    |                                 |
    | gRPC: SendCommand(mcCommandRequest)
    |-------------------------------->|
    |                                 | Process
    |                                 | Command
    |                                 |
    | mcCommandResponse               |
    |<--------------------------------|
    |                                 |

Broadcast Flow (Stream-Based)

+--------+                        +--------+
| Client |                        | Server |
+--------+                        +--------+
    |                                 |
    | SubscribeToBroadcast(Empty)     |
    |-------------------------------->|
    |                                 |
    | Stream Established              |
    |<--------------------------------|
    |                                 |
    | mcBroadcast Message 1           |
    |<--------------------------------|
    |                                 |
    | mcBroadcast Message 2           |
    |<--------------------------------|
    |          ...                    |

Example Usage

Server

// Create a gRPC server on port 50051
var server = new CommsServerGrpc("localhost", 50051);

// Start the server with a command handler
server.Start((request) => {
    Console.WriteLine($"Received command: {request.Id} - {request.Message}");
    return new CommandResponse(true, request.Id.ToString(), "Command processed");
});

// Send a broadcast message to all connected clients
server.SendBroadcast(new BroadcastMessage(1, "System notification"));

// Later, when application ends
server.Stop();

Client

// Create a gRPC client
var client = new CommsClientGrpc("localhost", 50051);

// Connect and set up broadcast message handler
var connected = await client.ConnectAsync((broadcast) => {
    Console.WriteLine($"Received broadcast: {broadcast.Id} - {broadcast.Message}");
});

if (connected)
{
    // Send a command
    var request = new CommandRequest(1, "Hello Server");
    var response = await client.SendCommandAsync(request);
    
    Console.WriteLine($"Response: {response.Success} - {response.Message}");
    
    // When done
    await client.DisconnectAsync();
}

Benefits of gRPC

  • High Performance: Uses HTTP/2 for multiplexing and Protocol Buffers for efficient serialization
  • Strong Typing: Contract-first approach with .proto files
  • Bi-directional Streaming: Perfect for real-time updates via broadcast
  • Language Agnostic: Clients and servers can be implemented in different languages
  • Generated Code: Reduces boilerplate and ensures type safety

Contents

  • gRPC services
  • Clients and servers
  • .proto files

Author

Joan Magnet

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.

Version Downloads Last Updated
1.0.9 137 9/2/2025
1.0.8 134 9/1/2025
1.0.7 84 8/22/2025
1.0.6 126 8/19/2025
1.0.5 62 8/16/2025
1.0.4 156 5/28/2025
1.0.3 153 5/28/2025
1.0.1 152 5/26/2025
1.0.0 155 5/26/2025