UdpArqClient.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace HPSocketCS
  5. {
  6. public class UdpArqClient : UdpClient
  7. {
  8. /// <summary>
  9. /// 创建socket监听&服务组件
  10. /// </summary>
  11. /// <returns></returns>
  12. protected override bool CreateListener()
  13. {
  14. if (IsCreate == true || pListener != IntPtr.Zero || pClient != IntPtr.Zero)
  15. {
  16. return false;
  17. }
  18. pListener = Sdk.Create_HP_UdpArqClientListener();
  19. if (pListener == IntPtr.Zero)
  20. {
  21. return false;
  22. }
  23. pClient = Sdk.Create_HP_UdpArqClient(pListener);
  24. if (pClient == IntPtr.Zero)
  25. {
  26. return false;
  27. }
  28. IsCreate = true;
  29. return true;
  30. }
  31. /// <summary>
  32. /// 终止服务并释放资源
  33. /// </summary>
  34. public override void Destroy()
  35. {
  36. Stop();
  37. if (pClient != IntPtr.Zero)
  38. {
  39. Sdk.Destroy_HP_UdpArqClient(pClient);
  40. pClient = IntPtr.Zero;
  41. }
  42. if (pListener != IntPtr.Zero)
  43. {
  44. Sdk.Destroy_HP_UdpArqClientListener(pListener);
  45. pListener = IntPtr.Zero;
  46. }
  47. IsCreate = false;
  48. }
  49. /// <summary>
  50. /// 获取或设置是否开启 NoDelay 模式
  51. /// </summary>
  52. public bool NoDelay
  53. {
  54. get
  55. {
  56. return Sdk.HP_UdpArqClient_IsNoDelay(pClient);
  57. }
  58. set
  59. {
  60. Sdk.HP_UdpArqClient_SetNoDelay(pClient, value);
  61. }
  62. }
  63. /// <summary>
  64. /// 获取或设置是否关闭拥塞控制
  65. /// </summary>
  66. public bool TurnoffCongestCtrl
  67. {
  68. get
  69. {
  70. return Sdk.HP_UdpArqClient_IsTurnoffCongestCtrl(pClient);
  71. }
  72. set
  73. {
  74. Sdk.HP_UdpArqClient_SetTurnoffCongestCtrl(pClient, value);
  75. }
  76. }
  77. /// <summary>
  78. /// 获取或设置数据刷新间隔
  79. /// </summary>
  80. public uint FlushInterval
  81. {
  82. get
  83. {
  84. return Sdk.HP_UdpArqClient_GetFlushInterval(pClient);
  85. }
  86. set
  87. {
  88. Sdk.HP_UdpArqClient_SetFlushInterval(pClient, value);
  89. }
  90. }
  91. /// <summary>
  92. /// 获取或设置快速重传 ACK 跨越次数
  93. /// </summary>
  94. public uint ResendByAcks
  95. {
  96. get
  97. {
  98. return Sdk.HP_UdpArqClient_GetResendByAcks(pClient);
  99. }
  100. set
  101. {
  102. Sdk.HP_UdpArqClient_SetResendByAcks(pClient, value);
  103. }
  104. }
  105. /// <summary>
  106. /// 获取或设置发送窗口大小
  107. /// </summary>
  108. public uint SendWndSize
  109. {
  110. get
  111. {
  112. return Sdk.HP_UdpArqClient_GetSendWndSize(pClient);
  113. }
  114. set
  115. {
  116. Sdk.HP_UdpArqClient_SetSendWndSize(pClient, value);
  117. }
  118. }
  119. /// <summary>
  120. /// 获取或设置接收窗口大小
  121. /// </summary>
  122. public uint RecvWndSize
  123. {
  124. get
  125. {
  126. return Sdk.HP_UdpArqClient_GetRecvWndSize(pClient);
  127. }
  128. set
  129. {
  130. Sdk.HP_UdpArqClient_SetRecvWndSize(pClient, value);
  131. }
  132. }
  133. /// <summary>
  134. /// 获取或设置最小重传超时时间
  135. /// </summary>
  136. public uint MinRto
  137. {
  138. get
  139. {
  140. return Sdk.HP_UdpArqClient_GetMinRto(pClient);
  141. }
  142. set
  143. {
  144. Sdk.HP_UdpArqClient_SetMinRto(pClient, value);
  145. }
  146. }
  147. /// <summary>
  148. /// 获取或设置最大传输单元
  149. /// </summary>
  150. public uint MaxTransUnit
  151. {
  152. get
  153. {
  154. return Sdk.HP_UdpArqClient_GetMaxTransUnit(pClient);
  155. }
  156. set
  157. {
  158. Sdk.HP_UdpArqClient_SetMaxTransUnit(pClient, value);
  159. }
  160. }
  161. /// <summary>
  162. /// 获取或设置最大数据包大小
  163. /// </summary>
  164. public uint MaxMessageSize
  165. {
  166. get
  167. {
  168. return Sdk.HP_UdpArqClient_GetMaxMessageSize(pClient);
  169. }
  170. set
  171. {
  172. Sdk.HP_UdpArqClient_SetMaxMessageSize(pClient, value);
  173. }
  174. }
  175. /// <summary>
  176. /// 获取或设置握手超时时间
  177. /// </summary>
  178. public uint HandShakeTimeout
  179. {
  180. get
  181. {
  182. return Sdk.HP_UdpArqClient_GetHandShakeTimeout(pClient);
  183. }
  184. set
  185. {
  186. Sdk.HP_UdpArqClient_SetHandShakeTimeout(pClient, value);
  187. }
  188. }
  189. /// <summary>
  190. /// 获取等待发送包数量
  191. /// </summary>
  192. /// <returns></returns>
  193. public int GetWaitingSendMessageCount()
  194. {
  195. var count = 0;
  196. if (Sdk.HP_UdpArqClient_GetWaitingSendMessageCount(pClient, ref count))
  197. {
  198. return count;
  199. }
  200. return 0;
  201. }
  202. }
  203. }