ITcpClientBase.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //------------------------------------------------------------------------------
  2. // 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
  3. // 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
  4. // CSDN博客:https://blog.csdn.net/qq_40374647
  5. // 哔哩哔哩视频:https://space.bilibili.com/94253567
  6. // Gitee源代码仓库:https://gitee.com/RRQM_Home
  7. // Github源代码仓库:https://github.com/RRQM
  8. // API首页:https://www.yuque.com/rrqm/touchsocket/index
  9. // 交流QQ群:234762506
  10. // 感谢您的下载和使用
  11. //------------------------------------------------------------------------------
  12. //------------------------------------------------------------------------------
  13. using System.IO;
  14. using System.Net.Security;
  15. using System.Net.Sockets;
  16. using TouchSocket.Core;
  17. namespace TouchSocket.Sockets
  18. {
  19. /// <summary>
  20. /// TCP终端基础接口。
  21. /// <para>
  22. /// 注意:该接口并不仅表示客户端。<see cref="SocketClient"/>也实现了该接口。
  23. /// </para>
  24. /// </summary>
  25. public interface ITcpClientBase : IClient, ISender, IDefaultSender, IPluginObject, IRequsetInfoSender
  26. {
  27. /// <summary>
  28. /// 缓存池大小
  29. /// </summary>
  30. int BufferLength { get; }
  31. /// <summary>
  32. /// 是否允许自由调用<see cref="SetDataHandlingAdapter"/>进行赋值。
  33. /// </summary>
  34. bool CanSetDataHandlingAdapter { get; }
  35. /// <summary>
  36. /// 客户端配置
  37. /// </summary>
  38. TouchSocketConfig Config { get; }
  39. /// <summary>
  40. /// 数据处理适配器
  41. /// </summary>
  42. DataHandlingAdapter DataHandlingAdapter { get; }
  43. /// <summary>
  44. /// 断开连接
  45. /// </summary>
  46. DisconnectEventHandler<ITcpClientBase> Disconnected { get; set; }
  47. /// <summary>
  48. /// 即将断开连接(仅主动断开时有效)。
  49. /// <para>
  50. /// 当主动调用Close断开时,可通过<see cref="TouchSocketEventArgs.IsPermitOperation"/>终止断开行为。
  51. /// </para>
  52. /// </summary>
  53. DisconnectEventHandler<ITcpClientBase> Disconnecting { get; set; }
  54. /// <summary>
  55. /// IP地址
  56. /// </summary>
  57. string IP { get; }
  58. /// <summary>
  59. /// 表示是否为客户端。
  60. /// </summary>
  61. bool IsClient { get; }
  62. /// <summary>
  63. /// 主通信器
  64. /// </summary>
  65. Socket MainSocket { get; }
  66. /// <summary>
  67. /// 判断是否在线
  68. /// <para>该属性仅表示TCP状态是否在线</para>
  69. /// </summary>
  70. bool Online { get; }
  71. /// <summary>
  72. /// 端口号
  73. /// </summary>
  74. int Port { get; }
  75. /// <summary>
  76. /// 接收模式
  77. /// </summary>
  78. public ReceiveType ReceiveType { get; }
  79. /// <summary>
  80. /// 使用Ssl加密
  81. /// </summary>
  82. bool UseSsl { get; }
  83. /// <summary>
  84. /// 中断终端
  85. /// </summary>
  86. void Close();
  87. /// <summary>
  88. /// 中断终端,传递中断消息
  89. /// </summary>
  90. /// <param name="msg"></param>
  91. void Close(string msg);
  92. /// <summary>
  93. /// 获取流,在正常模式下为<see cref="NetworkStream"/>,在Ssl模式下为<see cref="SslStream"/>。
  94. /// </summary>
  95. /// <returns></returns>
  96. Stream GetStream();
  97. /// <summary>
  98. /// 设置数据处理适配器
  99. /// </summary>
  100. /// <param name="adapter"></param>
  101. void SetDataHandlingAdapter(DataHandlingAdapter adapter);
  102. }
  103. }