您的位置:首页 > 娱乐 > 明星 > 期货量化交易客户端开源教学第八节——TCP通信服务类

期货量化交易客户端开源教学第八节——TCP通信服务类

2024/12/21 19:58:58 来源:https://blog.csdn.net/qq_35600909/article/details/140330253  浏览:    关键词:期货量化交易客户端开源教学第八节——TCP通信服务类

  private
    FReciveStr: AnsiString;     {接收到的数据}
    IsConErr: Boolean;      {网络连接是否失败}
    FSocket_LB: Integer;   {TCP连接类别,0为交易,1为行情,2为查询}
    FRetryCount: Integer; {网络连接重试次数}
    FLoginErrEvent: TLoginErrEvent;
    {心跳包定时器}
    procedure OnTimer_heatpack(Sender: TObject);
    {接收客户端发送的数据}
    procedure FTCP_serverClientRead(ReciveStr: AnsiString);
    procedure RunTCP_Conn_Event(connState: Boolean);
  public
    FBuffer_Port:array of Integer;
    Fbusiness_data: Tbuffer1024; {业务处理数据}
    Park_lenght: integer;    {收到的缓存包大小}
    buf_read: Tbuffer1024;  {读取到的字节}
    Timer_heatpack: TTimer; {心跳包定时器}
    FCMD_data: TMemoryStream;{指令数据}
    constructor Create(AOwner: TComponent);override;
    destructor Destroy; override;
    function open_service:Boolean; {打开服务}
    procedure RunLoginErrEvent;

    {TCP数据发送函数}
    procedure tcppark_sendbyte(Vdata : TMemoryStream);
    procedure cskt_Connect(Sender: TObject; Socket: TCustomWinSocket);
    procedure cskt_Disconnect(Sender: TObject;Socket: TCustomWinSocket);
    procedure cskt_Error(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure cskt_Read(Sender: TObject; Socket: TCustomWinSocket);
    procedure SetSocket_LB(Value:Integer);
    property Socket_LB: Integer read FSocket_LB write SetSocket_LB;
    property OnLoginErrEvent: TLoginErrEvent read FLoginErrEvent write FLoginErrEvent;
  end;
var
  VG_TCP_Client: TTCP_client_service;
  VG_TCP_Client_Market: TTCP_client_service;

implementation
uses
  ElAES,uMain, ulog, uMsgDlg, uLogin;


constructor TTCP_client_service.Create(AOwner: TComponent);
begin
  inherited Create(nil);
  FCMD_data := TMemoryStream.Create;{指令数据}
  IsConErr := False;
  FRetryCount := 0;

  Self.OnConnect := cskt_Connect;
  Self.OnDisconnect := cskt_Disconnect;
  Self.OnError := cskt_Error;
  Self.OnRead := cskt_Read;

  Timer_heatpack := TTimer.Create(nil); {心跳包定时器}
  Timer_heatpack.Enabled := False;
  Timer_heatpack.OnTimer := ONTimer_heatpack; {定时器}
  Timer_heatpack.Interval := TCP_heatpack_time;
end;

function TTCP_client_service.open_service:Boolean; {打开服务}
begin
  try
    Inc(FRetryCount);
    Active := False;
    ClientType := ctNonBlocking;
    Host := VGnetworkset.FnetaddressList[VGnetworkset.netindex].ip ;
    if (FSocket_LB = 0) or

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com