您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

102 行
2.4 KiB

  1. using System.IO;
  2. using System.Net;
  3. namespace MQTTnet.Server.Configuration
  4. {
  5. /// <summary>
  6. /// Listen Entry Settings Model
  7. /// </summary>
  8. public class TcpEndPointModel
  9. {
  10. /// <summary>
  11. /// Certificate settings.
  12. /// </summary>
  13. public CertificateSettingsModel Certificate { get; set; }
  14. /// <summary>
  15. /// Enabled / Disable
  16. /// </summary>
  17. public bool Enabled { get; set; } = true;
  18. /// <summary>
  19. /// Listen Address
  20. /// </summary>
  21. public string IPv4 { get; set; }
  22. /// <summary>
  23. /// Listen Address
  24. /// </summary>
  25. public string IPv6 { get; set; }
  26. /// <summary>
  27. /// Listen Port
  28. /// </summary>
  29. public int Port { get; set; } = 1883;
  30. /// <summary>
  31. /// Read IPv4
  32. /// </summary>
  33. /// <returns></returns>
  34. public bool TryReadIPv4(out IPAddress address)
  35. {
  36. if (IPv4 == "*")
  37. {
  38. address = IPAddress.Any;
  39. return true;
  40. }
  41. if (IPv4 == "localhost")
  42. {
  43. address = IPAddress.Loopback;
  44. return true;
  45. }
  46. if (IPv4 == "disable")
  47. {
  48. address = IPAddress.None;
  49. return true;
  50. }
  51. if (IPAddress.TryParse(IPv4, out var ip))
  52. {
  53. address = ip;
  54. return true;
  55. }
  56. throw new System.Exception($"Could not parse IPv4 address: {IPv4}");
  57. }
  58. /// <summary>
  59. /// Read IPv6
  60. /// </summary>
  61. /// <returns></returns>
  62. public bool TryReadIPv6(out IPAddress address)
  63. {
  64. if (IPv6 == "*")
  65. {
  66. address = IPAddress.IPv6Any;
  67. return true;
  68. }
  69. if (IPv6 == "localhost")
  70. {
  71. address = IPAddress.IPv6Loopback;
  72. return true;
  73. }
  74. if (IPv6 == "disable")
  75. {
  76. address = IPAddress.None;
  77. return true;
  78. }
  79. if (IPAddress.TryParse(IPv6, out var ip))
  80. {
  81. address = ip;
  82. return true;
  83. }
  84. throw new System.Exception($"Could not parse IPv6 address: {IPv6}");
  85. }
  86. }
  87. }