ProtobufOverUdp.Listener
1.1.1
See the version list below for details.
dotnet add package ProtobufOverUdp.Listener --version 1.1.1
NuGet\Install-Package ProtobufOverUdp.Listener -Version 1.1.1
<PackageReference Include="ProtobufOverUdp.Listener" Version="1.1.1" />
<PackageVersion Include="ProtobufOverUdp.Listener" Version="1.1.1" />
<PackageReference Include="ProtobufOverUdp.Listener" />
paket add ProtobufOverUdp.Listener --version 1.1.1
#r "nuget: ProtobufOverUdp.Listener, 1.1.1"
#:package ProtobufOverUdp.Listener@1.1.1
#addin nuget:?package=ProtobufOverUdp.Listener&version=1.1.1
#tool nuget:?package=ProtobufOverUdp.Listener&version=1.1.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 | 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
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- ProtobufOverUdp.Common (>= 1.0.3)
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- ProtobufOverUdp.Common (>= 1.0.3)
-
net9.0
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- ProtobufOverUdp.Common (>= 1.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.