need demo for new components

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
xalion
Posts: 124
Joined: Fri 20 May 2005 10:08

need demo for new components

Post by xalion » Fri 02 Apr 2021 04:01

as sb add more new components(TScSMTPClien,TScSSLServerConnection,TScTCPServer) in recent version.
but no demos,no docs to show how to use these new components.
please add demos add docs to these new components.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: need demo for new components

Post by ViktorV » Fri 02 Apr 2021 11:31

You may find an example of using the TScSMTPClient component on our forum: viewtopic.php?t=44303
Below is an example of using the TScSSLServerConnection and TScTCPServer components:

Code: Select all

unit DemoUnit;
interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  ScSSLServer, ScTCPServer, ScUtils, ScBridge;
type
  TDemoForm = class(TForm)
    btReadWriteSSL: TButton;
    procedure btReadWriteSSLClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    ScFileStorage: TScFileStorage;
    ScTCPServer: TScTCPServer;
    SSLServerConnection: TScSSLServerConnection;
    procedure DoAcceptConnection(Sender: TObject; Connection: TScTCPConnection; var Cancel: Boolean);
  end;
var
  DemoForm: TDemoForm;
implementation
{$R *.dfm}

procedure TDemoForm.DoAcceptConnection(Sender: TObject;
  Connection: TScTCPConnection; var Cancel: Boolean);
begin
  SSLServerConnection := TScSSLServerConnection.Create(Self);
  SSLServerConnection.Init(Connection);
  SSLServerConnection.Storage := ScFileStorage;
  ScFileStorage.Certificates.CertificateByName('server_cert').Key.Assign(ScFileStorage.Keys.KeyByName('server_key'));
  SSLServerConnection.CertNameChain := 'server_cert;cacert';
//  SSLServerConnection.CheckCertificateChain;
  SSLServerConnection.Connect;
  SSLServerConnection.IsSecure := True;
end;

procedure TDemoForm.FormCreate(Sender: TObject);
begin
  if ScFileStorage <> nil then
    Exit;
  ScFileStorage := TScFileStorage.Create(Self);
  ScTCPServer := TScTCPServer.Create(Self);
  ScTCPServer.BindAddress := '0.0.0.0';
  ScTCPServer.Port := 443;
  ScTCPServer.OnAcceptConnection := DoAcceptConnection;
  ScTCPServer.Start;
end;

procedure TDemoForm.btReadWriteSSLClick(Sender: TObject);
var
  RBuf, WBuf: TBytes;
  Count: integer;
begin
  if SSLServerConnection = nil then
    Exit;
  SetLength(RBuf, 1024);
  Count := SSLServerConnection.ReadBuffer(RBuf, 0, Length(RBuf));
  SetLength(WBuf, 1024);
  // Init WBuf
  // ...
  Count := SSLServerConnection.WriteBuffer(WBuf, 0, 100);
end;

end.
We plan to update the SecureBridge documentation shortly.

Post Reply