TradeTcpLinkProxy.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Muchinfo.TASClient.NetworkCore;
  2. using System;
  3. namespace Muchinfo.TASClient.Service.LinkProxy.TCP
  4. {
  5. /// <summary>
  6. /// 业务代理连接
  7. /// </summary>
  8. public class TradeTcpLinkProxy
  9. {
  10. private string _host; ////主机地址
  11. private int _port; ////通信端口号
  12. private TCPManager _tcpManager;
  13. /// <summary>
  14. /// 创建业务连接
  15. /// </summary>
  16. public TradeTcpLinkProxy(string host, int port)
  17. {
  18. _host = host;
  19. _port = port;
  20. _tcpManager = new TCPManager(new TradeTcpCallback());
  21. _tcpManager.Connect(_host, _port, ConnectSuccess, ConnectFail);
  22. }
  23. /// <summary>
  24. /// 连接失败
  25. /// </summary>
  26. /// <param name="errorCode">错误码</param>
  27. /// <param name="desc">连接描述</param>
  28. private void ConnectFail(int errorCode, string desc)
  29. {
  30. //todo:通知连接失败
  31. }
  32. /// <summary>
  33. /// 连接成功
  34. /// </summary>
  35. private void ConnectSuccess()
  36. {
  37. //todo:通知连接成功
  38. }
  39. /// <summary>
  40. /// 发送消息,
  41. /// </summary>
  42. /// <param name="package">消息内容</param>
  43. /// <param name="successAction">成功回复</param>
  44. /// <param name="failAction">错误回复</param>
  45. public void SendPackage(TCPPackage package, Action<TCPPackage> successAction, Action<int, string> failAction)
  46. {
  47. if (_tcpManager == null)
  48. {
  49. //todo:抛异常
  50. return;
  51. }
  52. _tcpManager.SendMessage(package, successAction, failAction);
  53. }
  54. }
  55. }