beacon
beacon copied to clipboard
Mono
Nice lib. But does not work on MONO. Are you still working on this lib?
It hasn't been updated in awhile -- but I have modified it to work in .NET CORE cross-platform (linux, etc). The reason it wouldn't work in Mono is because it's using Dispatch , which is purely a Windows thing.
I removed that for a more normalized event handling scenario that's "best practices" for the recent times -- I've also made it so that the beacon doesn't have to be on a random port (that beacons can all be on the same port) -- and added an identifier to the beacon (guid) that the probe can ignore (so it doesn't find its self).
This lets you run more than one beacon on the same address, with the same broadcast port -- which is great for Docker containers (why I did this) -- because you only need to open one port if you want these containers to find other containers on different hosts.
When I clean it up, I'll fork it and let you know, if you're still interested.
I am interested in your changes :D
Alright, I'll clean it up - update the README.MD and link the fork later sometime today.
Any update on this?
I would really appreciate a mono support.
Any news?
What is the problem? About what @jason-e-gross wrote:
The reason it wouldn't work in Mono is because it's using Dispatch , which is purely a Windows thing.
Are you referring to the example from README.md? Dispatcher.BeginInvoke((Action)(() => { ...
That is just an example and is not a requirement. It's likely there because of the WPF project BeaconWpfDialog, as it's needed there because of the UI interaction.
I ran it fine on .NET 8 (under Windows 10, 11, Linux), MAUI Android (Mono AFAIK) and .NET Core (Linux). Here is a snippet from my code that works just fine (async could be used instead, but I wanted to do it like this):
var resetEvent = new ManualResetEvent(false);
// Create probe
var probe = new Probe("beaconName");
// Look for beacon
probe.BeaconsUpdated += AttemptConnection;
probe.Start();
Console.WriteLine("Looking for beaconName beacon...");
void AttemptConnection(IEnumerable<BeaconLocation> beacons)
{
if (beacons != null && beacons.Any())
{
var beacon = beacons.First();
Console.WriteLine($"Found beacon at {beacon.Address}");
// Server connection code goes here
resetEvent.Set(); // Signal that the event has completed
probe.BeaconsUpdated -= AttemptConnection; // Remove the event handler
}
}
// Wait for the event to complete
resetEvent.WaitOne();
// Stop the probe
probe.Stop();