public void RemoveClient(MqttClient client) { lock (_syncLock) { _clientsArray.Remove(client); } }
public async void ConnectAsyncCallsSocketConnectWithDefaultParams() { var ip = "1.1.1.1"; var socketMock = new Mock<ISocketAdapter>(); var loggerMock = new Mock<ILogger>(); var client = new MqttClient(socketMock.Object, loggerMock.Object, SocketEncryption.None); var bldr = new MqttConnectMessageBuilder { ClientId = "UnitTest", CleanSession = true, Duplicate = false, KeepAliveTime = 15, UserName = "******", Password = "******", QualityOfService = QualityOfService.ExactlyOnce }; await client.ConnectWithMessageAsync(bldr, ip); socketMock.Verify(socket => socket.ConnectAsync( It.Is<string>(s => s.Equals(ip)), It.Is<int>(i => i == MqttProtocolInformation.Settings.Port), // Called with default port? It.Is<SocketEventArgs>(a => a != null) ), Times.Once()); }
public void AddClient(MqttClient client) { lock (_syncLock) { DoAddValidation(client); _clientsArray.Add(client); } }
/// <summary> /// Create an MQTT client the uses SSL encryption for communications. /// </summary> /// <param name="encryptionLevel">The encryption level to use.</param> /// <param name="caCertificate">The certificate for client authorities to use for authentication.</param> /// <returns></returns> public static MqttClient CreateSecureClient(SocketEncryption encryptionLevel, X509Certificate caCertificate) { var logManager = new LogCompositor(); ActiveClientCollection.Instance.TestCanAddNewClient(); // Each platform has its own implementation of Sockets and reader threads. var client = new MqttClient(new NetMfSocketAdapter(logManager, caCertificate), logManager, encryptionLevel); ActiveClientCollection.Instance.AddClient(client); return client; }
/// <summary> /// Create an MQTT client that does not use encryption for communications. /// </summary> /// <returns>An MQTT client ready to make connections to a broker.</returns> public static MqttClient CreateClient() { var logManager = new LogCompositor(); ActiveClientCollection.Instance.TestCanAddNewClient(); // Each platform has its own implementation of Sockets and reader threads. var client = new MqttClient(new NetMfSocketAdapter(logManager), logManager, SocketEncryption.None); ActiveClientCollection.Instance.AddClient(client); return client; }
/// <summary> /// Create an MQTT client the uses SSL encryption for communications. If the certificate is private and not /// signed ay a trusted Certificate Authority, the certificate must be installed in the application's /// certificate store ahead of making a connection. /// </summary> /// <param name="encryption">The encryption level to use.</param> /// <returns>An MQTT client ready to make secure connections to a broker.</returns> public static MqttClient CreateSecureClient(SocketEncryption encryption) { var logManager = new LogCompositor(); logManager.AddLoggingProvider(typeof(DebugLogger)); ActiveClientCollection.Instance.TestCanAddNewClient(); // Each platform has its own implementation of Sockets and reader threads. var client = new MqttClient(new WinRTSocketAdapter(logManager), logManager, encryption); ActiveClientCollection.Instance.AddClient(client); return client; }
public async void DisconnectAsyncCallsSocketSendMessageAsyncWithParams() { var socketMock = new Mock<ISocketAdapter>(); var loggerMock = new Mock<ILogger>(); var client = new MqttClient(socketMock.Object, loggerMock.Object, SocketEncryption.None); await client.DisconnectAsync(); socketMock.Verify(socket => socket.WriteAsync( It.Is<SocketEventArgs>(a => a != null && a.MessageToSend.MessageType == MessageType.Disconnect)), Times.Once()); }
public async void ConnectAsyncCallsSocketConnetWithGivenParams() { var ip = "1.1.1.1"; var port = 1883; var socketMock = new Mock<ISocketAdapter>(); var loggerMock = new Mock<ILogger>(); var client = new MqttClient(socketMock.Object, loggerMock.Object, SocketEncryption.None); var bldr = new MqttConnectMessageBuilder { ClientId = "UnitTest" }; await client.ConnectWithMessageAsync(bldr, ip, port); socketMock.Verify(socket => socket.ConnectAsync( It.Is<string>(s => s.Equals(ip)), // Called with passed in IP address? It.Is<int>(i => i == port), // Called with passed in port? It.Is<SocketEventArgs>(a => a != null) ), Times.Once()); // Called once and only once }
/// <summary> /// Perform any validation required before adding a client to the collection. /// Throw exceptions to indicate errors. /// </summary> /// <param name="client"></param> private void DoAddValidation(MqttClient client) { TestCanAddNewClient(); }
//private readonly MqttClient _mqtt; //private readonly SubscriptionItem _subscription; //private int _subMessageId; //private int _unsubMessageId; //public event MqttPublishMessageEventHandler OnMessage; //public event MqttMessageEventHandler CloseComplete; internal SubscriptionClient(MqttClient mqtt, SubscriptionItem subscription) { }