期货量化生意业务客户端开源教学第八节——TCP通信服务类 ...

梦应逍遥  金牌会员 | 2024-7-14 12:28:23 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 386|帖子 386|积分 1158

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

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

梦应逍遥

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表