DeliveryClient.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using Sers.Core.CL.MessageDelivery;
  3. using Vit.Core.Module.Log;
  4. namespace Sers.CL.Ipc.SharedMemory
  5. {
  6. public class DeliveryClient : IDeliveryClient
  7. {
  8. public DeliveryClient()
  9. {
  10. _conn = new DeliveryConnection();
  11. }
  12. /// <summary>
  13. /// 请勿处理耗时操作,需立即返回。接收到客户端的数据事件
  14. /// </summary>
  15. public Action<IDeliveryConnection, ArraySegment<byte>> Conn_OnGetFrame { set => _conn.OnGetFrame = value; }
  16. public Action<IDeliveryConnection> Conn_OnDisconnected { set => _conn.OnDisconnected = value; }
  17. readonly DeliveryConnection _conn;
  18. public IDeliveryConnection conn => _conn;
  19. //-------------------------------------------------------
  20. /// <summary>
  21. /// 共享内存名称
  22. /// </summary>
  23. public string name { get; set; } = "Sers.CL.Ipc";
  24. public void Close()
  25. {
  26. _conn.Close();
  27. }
  28. public bool Connect()
  29. {
  30. Logger.Info("[CL.Ipc] Ipc.SharedMemory,connecting", new { name });
  31. if (!_conn.InitAsClient(name))
  32. {
  33. Close();
  34. return false;
  35. }
  36. if (!_conn.Start())
  37. {
  38. Close();
  39. return false;
  40. }
  41. Logger.Info("[CL.Ipc] Ipc.SharedMemory,connected");
  42. return true;
  43. }
  44. }
  45. }