⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientmain.pas

📁 著名的SecureBlackBox控件完整源码
💻 PAS
字号:
unit ClientMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, uROIndyTCPChannel, uROIndyHTTPChannel, uROClient,
  uROBINMessage, IdComponent,
  ServerLibrary_Intf,
  StdCtrls, Buttons, ComCtrls, ExtCtrls, Spin, 
  IdBaseComponent, IdIOHandler, IdIOHandlerSocket, IdSSLOpenSSL,
  SBUtils, SBX509, SBIndyIOHandler, SBCustomCertStorage;

type
  TForm2 = class(TForm)
    ROBINMessage1: TROBINMessage;
    ROIndyHTTPChannel1: TROIndyHTTPChannel;
    cmdGetServerTime: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    edtFile: TEdit;
    Label1: TLabel;
    cmdUpload: TButton;
    cmdDownload: TButton;
    OpenDialog: TOpenDialog;
    cmdOpenFile: TButton;
    StatusBar: TStatusBar;
    ProgressBar: TProgressBar;
    ROIndyTCPChannel1: TROIndyTCPChannel;
    Edit3: TEdit;
    rgpChannel: TRadioGroup;
    Label2: TLabel;
    Label3: TLabel;
    Bevel1: TBevel;
    Label4: TLabel;
    edtPort: TSpinEdit;
    Label5: TLabel;
    eDownloadDir: TEdit;
    ElIndySSLIOHandler: TElIndySSLIOHandlerSocket;
    ServerCertStorage: TElMemoryCertStorage;
    ClientCertStorage: TElMemoryCertStorage;
    procedure cmdGetServerTimeClick(Sender: TObject);
    procedure cmdOpenFileClick(Sender: TObject);
    procedure cmdUploadClick(Sender: TObject);
    procedure cmdDownloadClick(Sender: TObject);
    procedure ROIndyHTTPChannel1InternalIndyClientWork(Sender: TObject;
      AWorkMode: TWorkMode; const AWorkCount: Integer);
    procedure ROBPDXHTTPChannel1InternalBPDXClientSendInProgress(
      ConnectTo: string; Bytes: Integer);
    procedure ROBPDXTCPChannel1InternalBPDXClientSendInProgress(
      ConnectTo: string; Bytes: Integer);
    procedure ElIndySSLIOHandlerCertificateValidate(Sender: TObject;
      Certificate: TElX509Certificate; var Validate: Boolean);
  private
    TransferSize: integer;
    function CreateService: IServerService;
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses uROTypes;

{$R *.dfm}

procedure TForm2.cmdGetServerTimeClick(Sender: TObject);
begin
  Edit2.Text := DateTimeToStr(CreateService.GetServerTime);
end;

function TForm2.CreateService: IServerService;
var
  channel: TROTransportChannel;
  message: TROMessage;
begin
  ROIndyHTTPChannel1.TargetURL := Edit1.Text;
  ROIndyHTTPChannel1.IndyClient.Port := edtPort.Value;

  ROIndyTCPChannel1.IndyClient.Host := Edit3.Text;
  ROIndyTCPChannel1.IndyClient.Port := edtPort.Value;

  case rgpChannel.ItemIndex of
    0: channel := ROIndyHTTPChannel1;
    1: channel := ROIndyTCPChannel1;
  end;

  message := ROBINMessage1;
  result := CoServerService.Create(message, channel);
end;

procedure TForm2.cmdOpenFileClick(Sender: TObject);
begin
  if OpenDialog.Execute then
  begin
    edtFile.Text := OpenDialog.FileName;
  end;
end;

procedure TForm2.cmdUploadClick(Sender: TObject);
var
  aFile: Binary;
begin
  aFile := Binary.Create;
  try
    aFile.LoadFromFile(edtFile.Text);
    TransferSize := aFile.Size;
    ProgressBar.Max := TransferSize;
    if CreateService.UploadAFile(ExtractFileName(edtFile.Text), aFile) then
      Statusbar.SimpleText := 'Upload Done'
    else Statusbar.SimpleText := 'Upload Error!';

    MessageDlg(Statusbar.SimpleText, mtInformation, [mbOK], 0)
  finally
    aFile.Free;
  end;
end;

procedure TForm2.cmdDownloadClick(Sender: TObject);
var
  aFile: Binary;
begin
  aFile := Binary.Create;
  try
    if CreateService.DownloadAFile(ExtractFileName(edtFile.Text), aFile) then
    begin
      if not DirectoryExists(eDownloadDir.Text)
        then CreateDir(eDownloadDir.Text);
        
      aFile.SaveToFile(IncludeTrailingBackslash(eDownloadDir.Text)+ExtractFileName(edtFile.Text));
      
      Statusbar.SimpleText := 'Download Done';
    end
    else Statusbar.SimpleText := 'Download Error!';

    MessageDlg(Statusbar.SimpleText, mtInformation, [mbOK], 0)
  finally
    aFile.Free;
  end;
end;

procedure TForm2.ROIndyHTTPChannel1InternalIndyClientWork(Sender: TObject;
  AWorkMode: TWorkMode; const AWorkCount: Integer);
begin
  ProgressBar.Position := AWorkCount;
  StatusBar.SimpleText := IntToStr(AWorkCount);
end;

procedure TForm2.ROBPDXHTTPChannel1InternalBPDXClientSendInProgress(
  ConnectTo: string; Bytes: Integer);
begin
  ProgressBar.Position := Bytes;
  StatusBar.SimpleText := IntToStr(Bytes);
end;

procedure TForm2.ROBPDXTCPChannel1InternalBPDXClientSendInProgress(
  ConnectTo: string; Bytes: Integer);
begin
  ProgressBar.Position := Bytes;
  StatusBar.SimpleText := IntToStr(Bytes);
end;

procedure TForm2.ElIndySSLIOHandlerCertificateValidate(Sender: TObject;
  Certificate: TElX509Certificate; var Validate: Boolean);
begin
  Validate := true;
  // NEVER do this in real life since this makes security void. 
  // Instead validate the certificate as described on http://www.eldos.com/sbb/articles/1966.php
end;


initialization

SetLicenseKey('ADDCD14AD06709806817E0B3D7BFD0A2222D536FE156466C5D5FE65DB5DEAE76' + 
  'FFDEBC07E915A5751C12C01C783958872A38E4A5EDA140E7247E0F2E56442A3C' + 
  'F3E9347AD8FDE52083A0DFC86BC00ECB0FD0CF1B51159A2BCB84F6EA6349EF47' + 
  '5C15A59AFCC55F7C3AAD26C279628B5D91B1DC94BD2385354A70CCA3B76101D9' + 
  'F41C84A639FC3CCE4BA8F0CC4A66DCD150114A3F58C1AD46B7B94643741BC20A' + 
  '8DCA83AB921480951B423CAA19EF1863A47CA2C3422E7E5634BED98939A5AE43' + 
  'DE1E4BAD79E66D8A5C973B3455656C8C9B6FF024FADD6CDA02D0F506D98493C8' + 
  'BD1ED7B237DB75FA31F2C82654490CDDDEE24E19939137B9E1DB05508733B22F');

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -