Flynk.Net.Services.Transmit.Grpc.Server
1.5.0
Prefix Reserved
dotnet add package Flynk.Net.Services.Transmit.Grpc.Server --version 1.5.0
NuGet\Install-Package Flynk.Net.Services.Transmit.Grpc.Server -Version 1.5.0
<PackageReference Include="Flynk.Net.Services.Transmit.Grpc.Server" Version="1.5.0" />
<PackageVersion Include="Flynk.Net.Services.Transmit.Grpc.Server" Version="1.5.0" />
<PackageReference Include="Flynk.Net.Services.Transmit.Grpc.Server" />
paket add Flynk.Net.Services.Transmit.Grpc.Server --version 1.5.0
#r "nuget: Flynk.Net.Services.Transmit.Grpc.Server, 1.5.0"
#:package Flynk.Net.Services.Transmit.Grpc.Server@1.5.0
#addin nuget:?package=Flynk.Net.Services.Transmit.Grpc.Server&version=1.5.0
#tool nuget:?package=Flynk.Net.Services.Transmit.Grpc.Server&version=1.5.0
Flynk.Net.Services.Transmit.Grpc.Server
Server-side gRPC hosting library for the Flynk Transmission Service. Provides ASP.NET Core integration, service configuration, and port management utilities.
Features
- ASP.NET Core gRPC service implementation
- Cross-process request/response with automatic correlation
- Flexible port configuration (separate HTTP/gRPC or shared)
- Port availability validation on startup
- Handler registry for request routing
- Security controls for client-to-client communication
Installation
dotnet add package Flynk.Net.Services.Transmit.Grpc.Server
This package automatically includes Flynk.Net.Services.Transmit.Grpc.Common for shared types.
Quick Start
1. Create ASP.NET Core Project
dotnet new web -n MyServer
cd MyServer
dotnet add package Flynk.Net.Services.Transmit.Grpc.Server
2. Configure Program.cs
using Flynk.Net.Services.Transmit.Grpc.Server;
using Flynk.Net.Services.Transmit.Grpc.Server.Extensions;
using Flynk.Net.Services.Transmit.Grpc.Client;
var builder = WebApplication.CreateBuilder(args);
// Add transmission service on port 5001
builder.AddTransmissionService(grpcPort: 5001);
var app = builder.Build();
// Map the gRPC endpoint
app.MapTransmissionService();
// Register server handler for incoming requests
RpcHandlerRegistry.RegisterServerHandler(async (request) =>
{
Console.WriteLine($"Received: {request.MessageType}");
return new TransmissionResponse
{
Id = Guid.NewGuid().ToString(),
CorrelationId = request.Id,
Success = true,
StatusCode = 200,
Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
};
}, serverId: "server");
app.Run();
3. Run
dotnet run
Configuration Options
Simple gRPC-Only Setup
builder.AddTransmissionService(grpcPort: 5001);
Separate REST and gRPC Ports
builder.AddTransmissionService(httpPort: 5000, grpcPort: 5001);
Full Configuration
builder.AddTransmissionService(options =>
{
options.HttpPort = 5000; // REST API port (HTTP/1.1)
options.GrpcPort = 5001; // gRPC port (HTTP/2)
options.Host = "0.0.0.0"; // Listen on all interfaces
options.ValidatePorts = true; // Check port availability
options.ServiceName = "MyServer"; // For error messages
options.UseHttps = false; // Enable HTTPS
});
Server Handler Registration
Basic Handler
RpcHandlerRegistry.RegisterServerHandler(async (request) =>
{
return request.MessageType switch
{
"ping" => CreateResponse(request, true, "pong"),
"echo" => CreateResponse(request, true, payload: request.Payload),
_ => CreateResponse(request, false, $"Unknown route: {request.MessageType}", 404)
};
}, serverId: "server");
Using RpcClient on Server
For typed routing on the server, use RpcClient with RegisterAsServerHandler():
var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
var logger = loggerFactory.CreateLogger<RpcClient>();
var serverClient = new RpcClient(
address: "http://localhost:5001",
id: "server",
logger: logger,
loggerFactory: loggerFactory // Enables TransmissionClient logging
);
// Register typed routes
serverClient.RegisterRoute<PingRequest, PongResponse>("ping",
async (request) =>
{
return Response<PongResponse>.OK(new PongResponse { Message = "pong" });
});
serverClient.RegisterRoute<CreateUserRequest, CreateUserResponse>("user.create",
async (request) =>
{
var user = await userService.CreateAsync(request);
return Response<CreateUserResponse>.OK(new CreateUserResponse { UserId = user.Id });
});
// Register as the server handler (handles requests without recipientId)
serverClient.RegisterAsServerHandler();
serverClient.StartListening();
Cross-Process Request/Response
When the server uses RequestAsync to send a request to a remote client (connected via the Receive stream), the server automatically waits for the client's response using correlation IDs. This enables synchronous RPC between the server and clients running in separate processes.
Server TransmissionServiceImpl Client (separate process)
| | |
|-- RequestAsync(recipientId) ------>| |
| (sets reply-to metadata) | |
| |-- Write to Receive stream -------->|
| | (registers pending request) |
| | |-- Process request
| | |
| |<-- Send(CorrelationId=requestId) --|
| | (completes pending request) |
|<-- actual response ----------------| |
The correlation is transparent — RequestAsync sets reply-to metadata automatically, and TransmissionServiceImpl handles the pending request lifecycle with a 120-second timeout.
Security: Client-to-Client Communication
By default, clients can only communicate with the server. This prevents unauthorized peer-to-peer messaging.
Enable Client-to-Client (if needed)
// Only enable if your application requires peer-to-peer messaging
RpcHandlerRegistry.EnableClientToClientCommunication();
Disable (default)
RpcHandlerRegistry.DisableClientToClientCommunication();
When disabled, attempts to send messages between clients return HTTP 403 (Forbidden).
Port Utilities
Check Port Availability
using Flynk.Net.Services.Transmit.Grpc.Utilities;
if (!PortUtility.IsPortAvailable(5001))
{
Console.WriteLine(PortUtility.CreatePortConflictMessage(5001, "MyServer"));
}
Find Available Port
var port = PortUtility.FindAvailablePort(5001, 5100);
if (port.HasValue)
{
Console.WriteLine($"Available port: {port}");
}
Adding REST Endpoints
The server can host both gRPC and REST endpoints:
var builder = WebApplication.CreateBuilder(args);
// Configure both HTTP (REST) and gRPC ports
builder.AddTransmissionService(httpPort: 5000, grpcPort: 5001);
var app = builder.Build();
// REST endpoints on port 5000
app.MapGet("/health", () => "OK");
app.MapGet("/api/status", () => new { Status = "Running" });
// gRPC endpoint on port 5001
app.MapTransmissionService();
app.Run();
Routing Priority
recipientIdis null/empty → Server handlerrecipientIdmatchesserverId→ Server handlerrecipientIdmatches registered client → Client handler (if enabled)- Client-to-client disabled → 403 Forbidden
- No match → 404 Not Found
Troubleshooting
Port Conflicts
If the server fails to start:
builder.AddTransmissionService(options =>
{
options.GrpcPort = 5001;
options.ValidatePorts = true; // Will throw on conflict
options.ServiceName = "MyServer"; // Better error messages
});
Handler Not Found
- Ensure
RpcHandlerRegistry.RegisterServerHandler()is called beforeapp.Run() - Verify route names match exactly (case-sensitive)
- Check
recipientIdis null/empty or matchesserverId
Connection Issues
Enable detailed logging:
var builder = WebApplication.CreateBuilder(args);
builder.Logging.SetMinimumLevel(LogLevel.Debug);
Client Package
For client applications, install the lightweight client package:
dotnet add package Flynk.Net.Services.Transmit.Grpc.Client
See the Client package documentation for usage.
License
This software is licensed under the Flynk Freeware License.
| Product | Versions 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 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. |
-
net8.0
- Flynk.Net.Services.Transmit.Grpc.Common (>= 1.5.0)
- Grpc.AspNetCore (>= 2.71.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
-
net9.0
- Flynk.Net.Services.Transmit.Grpc.Common (>= 1.5.0)
- Grpc.AspNetCore (>= 2.71.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.