ITcpService.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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;
  14. using TouchSocket.Core;
  15. namespace TouchSocket.Sockets
  16. {
  17. /// <summary>
  18. /// TCP系列服务器接口
  19. /// </summary>
  20. public interface ITcpService<TClient> : ITcpService where TClient : ISocketClient
  21. {
  22. /// <summary>
  23. /// 用户连接完成
  24. /// </summary>
  25. TouchSocketEventHandler<TClient> Connected { get; set; }
  26. /// <summary>
  27. /// 有用户连接的时候
  28. /// </summary>
  29. OperationEventHandler<TClient> Connecting { get; set; }
  30. /// <summary>
  31. /// 有用户断开连接
  32. /// </summary>
  33. DisconnectEventHandler<TClient> Disconnected { get; set; }
  34. /// <summary>
  35. /// 尝试获取TClient
  36. /// </summary>
  37. /// <param name="id">ID</param>
  38. /// <param name="socketClient">TClient</param>
  39. /// <returns></returns>
  40. bool TryGetSocketClient(string id, out TClient socketClient);
  41. }
  42. /// <summary>
  43. /// TCP服务器接口
  44. /// </summary>
  45. public interface ITcpService : IService, IIDSender, IIDRequsetInfoSender, IPluginObject
  46. {
  47. /// <summary>
  48. /// 当前在线客户端数量
  49. /// </summary>
  50. int Count { get; }
  51. /// <summary>
  52. /// 获取默认新ID。
  53. /// </summary>
  54. Func<string> GetDefaultNewID { get; }
  55. /// <summary>
  56. /// 获取最大可连接数
  57. /// </summary>
  58. int MaxCount { get; }
  59. /// <summary>
  60. /// 网络监听集合
  61. /// </summary>
  62. NetworkMonitor[] Monitors { get; }
  63. /// <summary>
  64. /// 获取当前连接的所有客户端
  65. /// </summary>
  66. SocketClientCollection SocketClients { get; }
  67. /// <summary>
  68. /// 使用Ssl加密
  69. /// </summary>
  70. bool UseSsl { get; }
  71. /// <summary>
  72. /// 清理当前已连接的所有客户端
  73. /// </summary>
  74. void Clear();
  75. /// <summary>
  76. /// 获取当前在线的所有ID集合
  77. /// </summary>
  78. /// <returns></returns>
  79. string[] GetIDs();
  80. /// <summary>
  81. /// 重置ID
  82. /// </summary>
  83. /// <param name="oldID"></param>
  84. /// <param name="newID"></param>
  85. /// <exception cref="ClientNotFindException"></exception>
  86. /// <exception cref="Exception"></exception>
  87. void ResetID(string oldID, string newID);
  88. /// <summary>
  89. /// 根据ID判断SocketClient是否存在
  90. /// </summary>
  91. /// <param name="id"></param>
  92. /// <returns></returns>
  93. bool SocketClientExist(string id);
  94. }
  95. }