-
Notifications
You must be signed in to change notification settings - Fork 2
/
MDNSService.cs
47 lines (40 loc) · 1.2 KB
/
MDNSService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Makaretu.Dns;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace EEBUS
{
public class MDNSService
{
private ServiceProfile serviceProfile = new ServiceProfile("Microsoft Azure EEBUS Gateway", "_ship._tcp", 50000);
public void AddProperty(string key, string value)
{
serviceProfile.AddProperty(key, value);
}
public void Run()
{
_ = Task.Run(async() =>
{
Thread.CurrentThread.IsBackground = true;
MulticastService mdns = new MulticastService();
ServiceDiscovery sd = new ServiceDiscovery(mdns);
try
{
mdns.Start();
sd.Advertise(serviceProfile);
await Task.Delay(-1).ConfigureAwait(false);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
sd.Dispose();
mdns.Stop();
}
});
}
}
}