| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using Muchinfo.TASClient.NetworkCore;
- using System;
- namespace Muchinfo.TASClient.Service.LinkProxy.TCP
- {
- /// <summary>
- /// 业务代理连接
- /// </summary>
- public class TradeTcpLinkProxy
- {
- private string _host; ////主机地址
- private int _port; ////通信端口号
- private TCPManager _tcpManager;
- /// <summary>
- /// 创建业务连接
- /// </summary>
- public TradeTcpLinkProxy(string host, int port)
- {
- _host = host;
- _port = port;
- _tcpManager = new TCPManager(new TradeTcpCallback());
- _tcpManager.Connect(_host, _port, ConnectSuccess, ConnectFail);
- }
- /// <summary>
- /// 连接失败
- /// </summary>
- /// <param name="errorCode">错误码</param>
- /// <param name="desc">连接描述</param>
- private void ConnectFail(int errorCode, string desc)
- {
- //todo:通知连接失败
- }
- /// <summary>
- /// 连接成功
- /// </summary>
- private void ConnectSuccess()
- {
- //todo:通知连接成功
- }
- /// <summary>
- /// 发送消息,
- /// </summary>
- /// <param name="package">消息内容</param>
- /// <param name="successAction">成功回复</param>
- /// <param name="failAction">错误回复</param>
- public void SendPackage(TCPPackage package, Action<TCPPackage> successAction, Action<int, string> failAction)
- {
- if (_tcpManager == null)
- {
- //todo:抛异常
- return;
- }
- _tcpManager.SendMessage(package, successAction, failAction);
- }
- }
- }
|