WatsonTcpClientSettings.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. namespace WatsonTcp
  2. {
  3. using System;
  4. /// <summary>
  5. /// Settings for Watson TCP client.
  6. /// </summary>
  7. public class WatsonTcpClientSettings
  8. {
  9. #region Public-Members
  10. /// <summary>
  11. /// Buffer size to use when reading input and output streams. Default is 65536. Value must be greater than zero.
  12. /// </summary>
  13. public int StreamBufferSize
  14. {
  15. get
  16. {
  17. return _StreamBufferSize;
  18. }
  19. set
  20. {
  21. if (value < 1) throw new ArgumentException("Stream buffer size must be greater than zero.");
  22. _StreamBufferSize = value;
  23. }
  24. }
  25. /// <summary>
  26. /// Client GUID.
  27. /// </summary>
  28. public Guid Guid { get; set; } = Guid.NewGuid();
  29. /// <summary>
  30. /// Maximum content length for streams that are proxied through a MemoryStream.
  31. /// If the content length exceeds this value, the underlying DataStream will be passed in the StreamReceived event.
  32. /// Value must be greater than zero.
  33. /// </summary>
  34. public int MaxProxiedStreamSize
  35. {
  36. get
  37. {
  38. return _MaxProxiedStreamSize;
  39. }
  40. set
  41. {
  42. if (value < 1) throw new ArgumentException("MaxProxiedStreamSize must be greater than zero.");
  43. _MaxProxiedStreamSize = value;
  44. }
  45. }
  46. /// <summary>
  47. /// Enable or disable message debugging. Requires `Logger` to be set.
  48. /// WARNING: Setting this value to true will emit a large number of log messages with a large amount of data.
  49. /// </summary>
  50. public bool DebugMessages { get; set; } = false;
  51. /// <summary>
  52. /// Method to invoke when sending a log message.
  53. /// </summary>
  54. public Action<Severity, string> Logger { get; set; } = null;
  55. /// <summary>
  56. /// Enable acceptance of SSL certificates from clients that cannot be validated.
  57. /// </summary>
  58. public bool AcceptInvalidCertificates { get; set; } = true;
  59. /// <summary>
  60. /// Require mutual authentication between SSL clients and this server.
  61. /// </summary>
  62. public bool MutuallyAuthenticate { get; set; } = false;
  63. /// <summary>
  64. /// Preshared key that must be consistent between clients and this server.
  65. /// </summary>
  66. public string PresharedKey { get; set; } = null;
  67. /// <summary>
  68. /// For Watson TCP client, the number of seconds to wait before timing out a connection attempt. Default is 5 seconds. Value must be greater than zero.
  69. /// </summary>
  70. public int ConnectTimeoutSeconds
  71. {
  72. get
  73. {
  74. return _ConnectTimeoutSeconds;
  75. }
  76. set
  77. {
  78. if (value < 1) throw new ArgumentException("ConnectTimeoutSeconds must be greater than zero.");
  79. _ConnectTimeoutSeconds = value;
  80. }
  81. }
  82. /// <summary>
  83. /// Maximum amount of time to wait before considering the server to be idle and disconnecting from it.
  84. /// By default, this value is set to 0, which will never disconnect due to inactivity.
  85. /// The timeout is reset any time a message is received from the server.
  86. /// For instance, if you set this value to 30000, the client will disconnect if the server has not sent a message to the client within 30 seconds.
  87. /// </summary>
  88. public int IdleServerTimeoutMs
  89. {
  90. get
  91. {
  92. return _IdleServerTimeoutMs;
  93. }
  94. set
  95. {
  96. if (value < 0) throw new ArgumentException("IdleClientTimeoutMs must be zero or greater.");
  97. _IdleServerTimeoutMs = value;
  98. }
  99. }
  100. /// <summary>
  101. /// Number of milliseconds to wait between each iteration of evaluating the server connection to see if the configured timeout interval has been exceeded.
  102. /// </summary>
  103. public int IdleServerEvaluationIntervalMs
  104. {
  105. get
  106. {
  107. return _IdleServerEvaluationIntervalMs;
  108. }
  109. set
  110. {
  111. if (value < 1) throw new ArgumentOutOfRangeException("IdleServerEvaluationIntervalMs must be one or greater.");
  112. _IdleServerEvaluationIntervalMs = value;
  113. }
  114. }
  115. /// <summary>
  116. /// Local TCP port.
  117. /// Set to '0' to have the underlying TcpClient implementation automatically assign.
  118. /// Value must be 0, or, 1024 or greater.
  119. /// </summary>
  120. public int LocalPort
  121. {
  122. get
  123. {
  124. return _LocalPort;
  125. }
  126. set
  127. {
  128. if (value < 0)
  129. {
  130. throw new ArgumentException("Valid values for LocalPort are 0, 1024-65535.");
  131. }
  132. else if (value > 0 && value < 1024)
  133. {
  134. throw new ArgumentException("Valid values for LocalPort are 0, 1024-65535.");
  135. }
  136. else if (value > 65535)
  137. {
  138. throw new ArgumentException("Valid values for LocalPort are 0, 1024-65535.");
  139. }
  140. _LocalPort = value;
  141. }
  142. }
  143. /// <summary>
  144. /// Nagle's algorithm. Disable the delay when send or receive buffers are not full. If true, disable the delay. Default is true.
  145. /// </summary>
  146. public bool NoDelay { get; set; } = true;
  147. #endregion
  148. #region Private-Members
  149. private int _StreamBufferSize = 65536;
  150. private int _MaxProxiedStreamSize = 67108864;
  151. private int _ConnectTimeoutSeconds = 5;
  152. private int _IdleServerTimeoutMs = 0;
  153. private int _IdleServerEvaluationIntervalMs = 1000;
  154. private int _LocalPort = 0;
  155. #endregion
  156. #region Constructors-and-Factories
  157. /// <summary>
  158. /// Instantiate.
  159. /// </summary>
  160. public WatsonTcpClientSettings()
  161. {
  162. }
  163. #endregion
  164. #region Public-Methods
  165. #endregion
  166. #region Private-Methods
  167. #endregion
  168. }
  169. }