AbstractTcpConnector.cs 924 B

123456789101112131415161718192021222324252627282930
  1. using DotNetty.Buffers;
  2. using DotNetty.Transport.Channels;
  3. using System;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Team.Communicate
  7. {
  8. public abstract class AbstractTcpConnector
  9. {
  10. protected IByteBuffer ByteBuffers;
  11. private Encoding _encoding;
  12. public virtual Encoding Encoding
  13. {
  14. get => _encoding ?? Encoding.UTF8;
  15. set => _encoding = value;
  16. }
  17. public virtual void SetEnd(string endWith)
  18. {
  19. var bytes = Encoding.GetBytes(endWith);
  20. var sendBytes = Unpooled.Buffer();
  21. sendBytes.WriteBytes(bytes);
  22. ByteBuffers = sendBytes;
  23. }
  24. public abstract void UseUnRegisterMessage(string key);
  25. public abstract void Register(string id, Func<string, IChannelHandlerContext, ValueTask<string>> func);
  26. public abstract void UnRegister(string id);
  27. }
  28. }