ProtobufOverUdp.Common
1.0.1
See the version list below for details.
dotnet add package ProtobufOverUdp.Common --version 1.0.1
NuGet\Install-Package ProtobufOverUdp.Common -Version 1.0.1
<PackageReference Include="ProtobufOverUdp.Common" Version="1.0.1" />
<PackageVersion Include="ProtobufOverUdp.Common" Version="1.0.1" />
<PackageReference Include="ProtobufOverUdp.Common" />
paket add ProtobufOverUdp.Common --version 1.0.1
#r "nuget: ProtobufOverUdp.Common, 1.0.1"
#:package ProtobufOverUdp.Common@1.0.1
#addin nuget:?package=ProtobufOverUdp.Common&version=1.0.1
#tool nuget:?package=ProtobufOverUdp.Common&version=1.0.1
ProtobufOverUdp
A small .NET helper library that makes it easy to send and receive Protocol Buffers messages over UDP.
It wraps UdpClient and Google.Protobuf behind a simple API, so you can focus on your message contracts instead of byte arrays, ports and parsing.
📦 Installation
Common package includes UdpService which is necessary to Send protobuf messages over UDP.
NuGet link: ProtobufOverUdp.Common
dotnet add package ProtobufOverUdp.Common
Listener package includes UdpListener and interface IUdpMessageHandler which is necessary to Receive protobuf messages over UDP and handle them properly.
NuGet link: ProtobufOverUdp.Listener
dotnet add package ProtobufOverUdp.Listener
Usage
Send protobuf over UDP
To send protobuf messages over UDP, download ProtobufOverUdp.Common NuGet package, then add necessary services in your Program.cs
builder.Services.AddUdpService(builder.Configuration);
Now, you can inject IUdpService and send protobuf messages via UDP this way:
await udpService.SendMessageAsync(message, request.IpAddress, request.Port);
If you have the same target IP address and port everywhere, you can specify them this way:
builder.Services.AddUdpService(builder.Configuration, opt =>
{
opt.DestinationIpAddress = "127.0.0.1";
opt.DestinationPort = 5123;
});
Now, you can simply use the method this way:
await udpService.SendMessageAsync(message);
Receive protobuf over UDP
To receive protobuf messages over UDP, download ProtobufOverUdp.Listener NuGet package, then add necessary services in your Program.cs
builder.Services.AddUdpService(context.Configuration);
builder.Services.AddUdpListener();
Now, for each protobuf type you should have its own UdpMessageHandler. Implement them in a similar way (Notification here is your message):
public sealed class NotificationUdpMessageHandler(ILogger<StatusUdpMessageHandler> logger) : IUdpMessageHandler<Notification>
{
public Task HandleAsync(Notification message, CancellationToken token)
{
if (logger.IsEnabled(LogLevel.Information))
{
logger.LogInformation("Received notification {Id} {Text}; Current Time: {CurrentTime}.", message.Id,
message.Text, DateTimeOffset.UtcNow);
}
return Task.CompletedTask;
}
}
Finally, register them in DI:
builder.Services.AddUdpMessageHandler<Notification, NotificationUdpMessageHandler>();
Now, your application will listen to coming UDP messages and handle them properly.
Demo
There are ListenerDemo and PublisherDemo projects. You can run them to see how this application works.
dotnet run --project .\src\ListenerDemo\ListenerDemo.csproj --launch-profile "ListenerDemo"
dotnet run --project .\src\PublisherDemo\PublisherDemo.csproj --launch-profile "http"
Now, you can use Postman collection (download it from PostmanCollections folder or from this link)
| Product | Versions 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 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 is compatible. 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. |
-
net10.0
- Google.Protobuf (>= 3.33.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
-
net6.0
- Google.Protobuf (>= 3.33.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
-
net7.0
- Google.Protobuf (>= 3.33.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
-
net8.0
- Google.Protobuf (>= 3.33.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
-
net9.0
- Google.Protobuf (>= 3.33.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ProtobufOverUdp.Common:
| Package | Downloads |
|---|---|
|
ProtobufOverUdp.Listener
ProtobufOverUdp.Listener is a useful library for receiving and parsing protobufs. |
GitHub repositories
This package is not used by any popular GitHub repositories.