beacon icon indicating copy to clipboard operation
beacon copied to clipboard

Mono

Open JTrotta opened this issue 6 years ago • 7 comments

Nice lib. But does not work on MONO. Are you still working on this lib?

JTrotta avatar Mar 18 '18 20:03 JTrotta

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.

jason-e-gross avatar Dec 10 '19 16:12 jason-e-gross

I am interested in your changes :D

Tzian avatar Dec 10 '19 16:12 Tzian

Alright, I'll clean it up - update the README.MD and link the fork later sometime today.

jason-e-gross avatar Dec 10 '19 16:12 jason-e-gross

Any update on this?

Tzian avatar Feb 12 '20 22:02 Tzian

I would really appreciate a mono support.

cevataykans avatar Oct 04 '20 21:10 cevataykans

Any news?

BruceKristelijn avatar Nov 27 '21 18:11 BruceKristelijn

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();

Versette avatar Aug 15 '23 22:08 Versette