Indy tcp client

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBAccess, MyAccess, StdCtrls, ComCtrls, ExtCtrls, MemDS,
  MyRec, OBRARCompress, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, jpeg , inifiles;

type
  TForm1 
=   class (TForm)
    MyConnection1: TMyConnection;
    pb1: TProgressBar;
    
Next : TButton;
    s: TButton;
    Panel1: TPanel;
    MyTable1: TMyTable;
    MyTable1id: TIntegerField;
    MyTable1path: TStringField;
    MyTable1pic: TStringField;
    OBRARCompress1: TOBRARCompress;
    IdTCPClient1: TIdTCPClient;
    Image1: TImage;
    procedure sClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure NotBt;
    procedure OBRARCompress1Compressing(Sender: TObject;
      Progress: 
Integer );
    procedure upload(
const  FFileName :  string );  
    procedure NextClick(Sender: TObject);
  
private
    { 
Private  declarations }
  
public
    { 
Public  declarations }
  
end ;

var
  Form1: TForm1;
  doing: 
Integer ;
  inifile : Tinifile;
implementation

{$R 
* .dfm}

procedure TForm1.sClick(Sender: TObject);
begin
  Close;
end ;

procedure TForm1.FormCreate(Sender: TObject);
begin
  doing :
=   1 ;
  inifile :
=  Tinifile.Create(ExtractFilePath(paramstr( 0 )) + ' config.ini');
end ;

procedure TForm1.NotBt;
begin
  
Next .Enabled: =   not   Next .Enabled;
end ;

procedure TForm1.OBRARCompress1Compressing(Sender: TObject;
  Progress: 
Integer );
begin
  pb1.Position :
=  Progress;
  Application.ProcessMessages;
end ;

procedure TForm1.upload(
const  FFileName :  string );
var
  Buf : array[
0 .. 1023 of   Byte ;
  aSize, ReadCount, Tmpint : 
Integer ;
  aStream : TFileStream;
  aIdTCPClient: TIdTCPClient;
begin
try
  aStream :
=  TFileStream.Create(FFileName, fmOpenRead  or  fmShareDenyWrite);
  aIdTCPClient :
=   TIdTCPClient.Create(Application);
  aIdTCPClient.Port :
=  StrToInt(inifile.readstring( ' Server','Port','3303'));
  aIdTCPClient.Host : =  inifile.readstring( ' Server','Host','59.36.101.91');
  aIdTCPClient.Connect;
  pb1.Position :
=   0 ;
    
// 发送文件名
  aIdTCPClient.WriteLn(
' SEND:'+ExtractFileName(FFileName));
     // 等待接受确认
    aIdTCPClient.ReadLn(#
13 # 10 1000 );
    
// 写文件长度和文件流
    aSize :
=  aStream.Size;
    pb1.Max :
=  aSize;
    aIdTCPClient.WriteBuffer(aSize, 
4 );
        
while  aStream.Position  <  aStream.Size  do
        begin
          
if  aStream.Size  -  aStream.Position  >=  SizeOf(Buf)  then
              ReadCount :
=  sizeOf(Buf)
          
else  ReadCount : =  aStream.Size  -  aStream.Position;
          pb1.Position :
=   aStream.Position;
          aStream.ReadBuffer(Buf, ReadCount);
          aIdTCPClient.WriteBuffer(Buf, ReadCount);
        
end ;
        aIdTCPClient.ReadLn;
        aIdTCPClient.Disconnect;
  
finally
  aIdTCPClient.Disconnect;
  
if  aStream <> nil  then  FreeAndNil(aStream);
  
if  aIdTCPClient <> nil  then  FreeAndNil(aIdTCPClient);
  
end ;
end ;

procedure TForm1.NextClick(Sender: TObject);
var
  Myrec:TMyrec;
  Rec:TPersonRec;
  Tp:TSearchRec;
  Tct:_SystemTime;
  filename:
string ;
begin
case  doing  of
1 :
  begin
  NotBt;
  MyTable1.Active :
=   True ;
  Myrec :
=  TMyrec.Create( ' rec.dat',fmCreate or fmShareDenyWrite);
  pb1.Max : =  MyTable1.RecordCount;
  
while   not  MyTable1.Eof  do
    begin
    Rec.id :
= varToStr(MyTable1.FieldValues[ ' id']);
    Rec.path : = varToStr(MyTable1.FieldValues[ ' path']);
    Rec.pic : = varToStr(MyTable1.FieldValues[ ' pic']);
     if  Rec.pic  <> ' ' then
      begin
      filename :
=  inifile.readstring( ' CONFIG','DataPath','E:yipartswwwDATAxG5ARCZH6c') + '/'+ varToStr(MyTable1.FieldValues['path']) + '/' + varToStr(MyTable1.FieldValues['pic']);
      FindFirst(filename,faAnyFile,Tp);
      FileTimeToSystemTime(Tp.FindData.ftLastWriteTime,Tct);
      Rec.tdate :
=   FormatDateTime ( ' YYYYMMDDHHMMSS',SystemTimeToDateTime(Tct));
       end ;
    Myrec.AppandRec(Rec);
    pb1.Position :
=  pb1.Position  + 1 ;
    MyTable1.Next;
    
end ; // while
    Myrec.Free;
    Panel1.Caption :
=   ' 开始压缩';
    pb1.Position : =   0 ;
    pb1.Max :
=   100 ;
    OBRARCompress1.OnCompressing:
= OBRARCompress1Compressing;
    OBRARCompress1.SourceFiles.Add(ExtractFilePath(paramstr(
0 )) + ' rec.dat');
    OBRARCompress1.RARFileName : =  ExtractFilePath(paramstr( 0 )) + ' rec.rar';
    OBRARCompress1.Compress;
    Panel1.Caption :
=   ' 记录文件生成完成,开始上传至服务器。';
    upload(ExtractFilePath(paramstr( 0 )) + ' rec.rar');
    Panel1.Caption : =   ' 记录文件已上传至服务器,服务器开始分析。';
   end ; // case   1 :
end ; // case  doing  of
end ;

end .
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值