/// <summary> /// Constructor /// </summary> /// <param name="commLayer">Communication layer to use (TCP)</param> /// <param name="settings">Broker settings</param> public MqttBroker(IMqttCommunicationLayer commLayer, MqttSettings settings) { // MQTT broker settings this.settings = settings; // MQTT communication layer this.commLayer = commLayer; this.commLayer.ClientConnected += commLayer_ClientConnected; // create managers (publisher, subscriber, session and UAC) this.subscriberManager = new MqttSubscriberManager(); this.sessionManager = new MqttSessionManager(); this.publisherManager = new MqttPublisherManager(this.subscriberManager, this.sessionManager); this.uacManager = new MqttUacManager(); this.clients = new MqttClientCollection(); }
/// <summary> /// MqttClient initialization /// </summary> /// <param name="brokerHostName">Broker host name</param> /// <param name="brokerIpAddress">Broker IP address</param> /// <param name="brokerPort">Broker port</param> /// <param name="secure">>Using secure connection</param> /// <param name="caCert">CA certificate for secure connection</param> private void Init(string brokerHostName, IPAddress brokerIpAddress, int brokerPort, bool secure, X509Certificate caCert) { #if SSL // check security parameters if ((secure) && (caCert == null)) throw new ArgumentException("Secure requested but CA certificate is null !"); #else if (secure) throw new ArgumentException("Library compiled without SSL support"); #endif this.brokerHostName = brokerHostName; // if broker hostname is null, set ip address if (this.brokerHostName == null) this.brokerHostName = brokerIpAddress.ToString(); this.brokerIpAddress = brokerIpAddress; this.brokerPort = brokerPort; this.secure = secure; #if SSL // if secure, load CA certificate if (this.secure) { this.caCert = caCert; } #endif // reference to MQTT settings this.settings = MqttSettings.Instance; this.syncEndReceiving = new AutoResetEvent(false); this.keepAliveEvent = new AutoResetEvent(false); // queue for handling inflight messages (publishing and acknowledge) this.inflightWaitHandle = new AutoResetEvent(false); this.inflightQueue = new Queue(); // queue for received message this.receiveEventWaitHandle = new AutoResetEvent(false); this.receiveQueue = new Queue(); this.internalQueue = new Queue(); }
/// <summary> /// Constructor /// </summary> /// <param name="socket">Raw socket for communication</param> public MqttClient(Socket socket) { this.channel = new MqttNetworkChannel(socket); // reference to MQTT settings this.settings = MqttSettings.Instance; // client not connected yet (CONNACK not send from client), some default values this.IsConnected = false; this.ClientId = null; this.CleanSession = true; this.keepAliveEvent = new AutoResetEvent(false); // queue for handling inflight messages (publishing and acknowledge) this.inflightWaitHandle = new AutoResetEvent(false); this.inflightQueue = new Queue(); // queue for received message this.receiveEventWaitHandle = new AutoResetEvent(false); this.receiveQueue = new Queue(); this.internalQueue = new Queue(); }
public MqttBrokerWithReceiverCallback(IMqttCommunicationLayer commLayer, MqttSettings settings) : base(commLayer, settings) { }