WingMan – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Net; |
||
5 | using System.Text; |
||
6 | using System.Threading.Tasks; |
||
7 | using MQTTnet; |
||
8 | using MQTTnet.Server; |
||
9 | |||
10 | namespace WingMan.Host |
||
11 | { |
||
12 | public class MQTTServer |
||
13 | { |
||
14 | private IMqttServer Server { get; set; } |
||
15 | public bool ServerRunning { get; set; } |
||
16 | |||
17 | public MQTTServer() |
||
18 | { |
||
19 | Server = new MqttFactory().CreateMqttServer(); |
||
20 | } |
||
21 | |||
22 | public async Task Stop() |
||
23 | { |
||
24 | await Server.StopAsync().ConfigureAwait(false); |
||
25 | |||
26 | ServerRunning = false; |
||
27 | } |
||
28 | |||
29 | public async Task Start(IPAddress ipAddress, int port) |
||
30 | { |
||
31 | var optionsBuilder = new MqttServerOptionsBuilder() |
||
32 | .WithDefaultEndpointBoundIPAddress(ipAddress) |
||
33 | .WithDefaultEndpointPort(port); |
||
34 | |||
35 | await Server.StartAsync(optionsBuilder.Build()).ConfigureAwait(false); |
||
36 | |||
37 | ServerRunning = true; |
||
38 | } |
||
39 | } |
||
40 | } |