IwbM2MsgClient.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 
  2. using System;
  3. using System.Web.WebPages;
  4. using Abp.UI;
  5. using uPLibrary.Networking.M2Mqtt;
  6. namespace IwbZero.M2MClient
  7. {
  8. public class IwbM2MsgClient
  9. {
  10. private uPLibrary.Networking.M2Mqtt.MqttClient Client { get; set; }
  11. private int ConnectedCount { get; set; }
  12. private readonly object _lock = new object();
  13. private int HasReconnectCount { get; set; }
  14. public string ServerIp { get; set; }
  15. public int ServerPort { get; set; }
  16. public string ClientId { get; set; }
  17. public string ServerUserId { get; set; }
  18. public string ServerPassword { get; set; }
  19. public bool NotValidate => (ServerIp.IsEmpty() || ServerPort == 0 || ServerIp.IsEmpty() ||
  20. ClientId.IsEmpty() || ServerUserId.IsEmpty() || ServerPassword.IsEmpty());
  21. public void SetOptions(string serverIp, int serverPort, string clientId, string serverUserId, string serverPassword)
  22. {
  23. ServerIp = serverIp;
  24. ServerPort = serverPort;
  25. ClientId = clientId;
  26. ServerUserId = serverUserId;
  27. ServerPassword = serverPassword;
  28. }
  29. private void CreateClient()
  30. {
  31. if (NotValidate)
  32. {
  33. throw new UserFriendlyException("客户端配置参数不合法,请检查后再试!");
  34. }
  35. var client = new uPLibrary.Networking.M2Mqtt.MqttClient(ServerIp, ServerPort, false, null, null, MqttSslProtocols.None);
  36. }
  37. }
  38. }