Eiredynamic.Pharos
1.0.0
dotnet add package Eiredynamic.Pharos --version 1.0.0
NuGet\Install-Package Eiredynamic.Pharos -Version 1.0.0
<PackageReference Include="Eiredynamic.Pharos" Version="1.0.0" />
<PackageVersion Include="Eiredynamic.Pharos" Version="1.0.0" />
<PackageReference Include="Eiredynamic.Pharos" />
paket add Eiredynamic.Pharos --version 1.0.0
#r "nuget: Eiredynamic.Pharos, 1.0.0"
#:package Eiredynamic.Pharos@1.0.0
#addin nuget:?package=Eiredynamic.Pharos&version=1.0.0
#tool nuget:?package=Eiredynamic.Pharos&version=1.0.0
Pharos
Pharos is a .NET discovery library that enables beacon/probe detection and serialized message exchange. It provides a lightweight, serverless solution for service discovery and message broadcasting using UDP multicast.
Overview
The library consists of two main components:
- Beacon: Broadcasts messages to the network at configurable intervals.
- Probe: Listens for and receives broadcasted messages.
Use Cases
- Simple serverless messaging.
- Server discovery (Building block for consensus algorithms).
- Service mesh discovery.
- Network presence detection.
Installation
Pharos targets .NET Standard 2.0 for maximum compatibility and can be used in projects targeting:
- .NET Core 2.0+
- .NET 5.0+
- .NET Framework 4.6.1+
NuGet Installation
# Install via NuGet
dotnet add package Eiredynamic.Pharos
Quick Start
Basic Usage
// Create a message to broadcast
var message = "hello Pharos!";
// Start broadcasting messages (Beacon)
var beacon = new Beacon<string>();
await beacon.SendBeacon(cancellationToken, message);
// Listen for messages (Probe)
var probe = new Probe<string>();
await foreach (var receivedMessage in probe.StartReceiving(cancellationToken))
{
Console.WriteLine($"Received message from {receivedMessage.Hostname}");
}
Generic Messages
While string is used above and PharosSampleMessage
is provided as a reference implementation, you can use any class as a message type as long as it meets these requirements:
- The class must be serializable (compatible with Newtonsoft.Json).
- The class must be a reference type with a parameterless constructor (
where T : class, new()
). However, this does not guarantee JSON compatibility—ensure all properties are serializable and avoid complex object graphs where possible.
Example of a minimal generic message:
public class CustomMessage
{
public Guid Id { get; init; } = Guid.NewGuid();
public string Data { get; set; } = string.Empty;
}
Network Efficiency Tips
To minimize network overhead:
- Use compact property names.
- Include only essential data fields.
- Consider using value types (
int
,Guid
) over strings where possible. - Avoid nested complex objects unless necessary.
Example usage:
// Create your custom message
var message = new CustomMessage { Data = "Hello" };
// Use with Beacon
var beacon = new Beacon<CustomMessage>();
await beacon.SendBeacon(cancellationToken, message);
// Use with Probe
var probe = new Probe<CustomMessage>();
await foreach (var received in probe.StartReceiving(cancellationToken))
{
Console.WriteLine($"Received: {received.Data}");
}
Your message type will be automatically serialized for network transmission and deserialized upon receipt.
Configuration
The library can be configured using ConfigOptions
:
var config = new ConfigOptions
{
DestinationPort = 12345,
SourcePort = 0, // Dynamic port allocation
MulticastIP = IPAddress.Parse("239.0.0.1"),
BeaconInterval = 5000 // Milliseconds
};
Features
- Generic Message Support: Both Beacon and Probe support generic message types.
- Cancellation Support: All operations support graceful cancellation.
- Configurable Intervals: Customize beacon broadcast intervals.
- NAT Considerations: Pharos uses UDP multicast for discovery, which may require additional configuration when crossing NAT boundaries.
- Logging Integration: NLog integration for diagnostic logging.
Example Application
The solution includes an example application demonstrating basic usage.
Requirements
- .NET Standard 2.0 compatible runtime.
- A network that supports UDP multicast.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.4)
- Newtonsoft.Json (>= 13.0.3)
- NLog (>= 5.4.0)
- NLog.Extensions.Logging (>= 5.4.0)
- NLog.Schema (>= 5.4.0)
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 0 | 4/25/2025 |