Indy tcp client
来源:互联网 发布:微信视频打赏平台源码 编辑:程序博客网 时间:2024/05/16 04:27
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.
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.
- Indy tcp client
- Indy-Client TIdHttp例子
- Indy tcp server
- Indy Client / Server 程序示例
- TCP client
- TCP Client
- TCP--client
- indy tcp的即时通讯的问题
- indy
- Indy TCP/IP 组件里的几个常用方法
- Delphi2009的Indy全接触之TCP篇
- Delphi中关于TCP通讯,Indy粘数据包问题
- Delphi2009的Indy全接触之TCP篇
- 关于Delphi中Indy控件,TCP通信实时性问题
- tcp client in c
- java Tcp Client server
- TCP(socket vc) client
- C++ TCP Client
- duniya vm 完成
- 继续无聊
- 用DELPHI实现文件加密压缩
- 把Oracle中的数据导到文本文件
- Indy tcp server
- Indy tcp client
- 对数学的思考(转载)
- SQL Server 2005 学习笔记--SSIS篇(2)
- CSS盒子模式详解1
- Lucene.Net系列一 ---simple example
- Lucene.net 系列二 --- index (上)
- 空手道及主要流派简介
- Lucene.net 系列三 --- index 中
- Lucene.net 系列四 --- index 下