MQTT - Start Server
Even though you have installed the XSockets.Mqtt package MQTT will not be enabled by default. You have to Start/Stop the MQTT server when you Start/Stop XSockets.
The Start/Stop is done on the MqttManager
.
Start
using XSockets.Core.Common.Socket;
using XSockets.Plugin.Framework;
using XSockets.Protocol.Mqtt.Modules.Controller;
((MqttManager)Composable.GetExport<IXSocketController>(typeof(MqttManager))).Start();
Stop
using XSockets.Core.Common.Socket;
using XSockets.Plugin.Framework;
using XSockets.Protocol.Mqtt.Modules.Controller;
((MqttManager)Composable.GetExport<IXSocketController>(typeof(MqttManager))).Stop();
Example
A simple example on how to start/stop MQTT when you start/stop XSockets.
The example assumes that you have installed XSockets
and XSockets.MQTT
from nuget
using System;
using XSockets.Core.Common.Socket;
using XSockets.Plugin.Framework;
using XSockets.Protocol.Mqtt.Modules.Controller;
class Program
{
static void Main(string[] args)
{
using (var container = Composable.GetExport<IXSocketServerContainer>())
{
var mqtt = ((MqttManager)Composable.GetExport<IXSocketController>(typeof(MqttManager)));
container.Start();
mqtt.Start();
Console.ReadLine();
container.Stop();
mqtt.Stop();
}
}
}