Minimal SSL TCPServer and client
I am using delphi version 10.3.1 .
No certificate, it is not mandatory.
No errormessages, but only rubbish received in ServerExecute. Works fine when UseSSL = false;
Any ideas?
Place a button on an empty form, and link it to Button1Click.
I am using delphi version 10.3.1 .
No certificate, it is not mandatory.
No errormessages, but only rubbish received in ServerExecute. Works fine when UseSSL = false;
Any ideas?
Place a button on an empty form, and link it to Button1Click.
Code:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uIdContext, IdContext,
IdServerIOHandler, IdSSL, IdSSLOpenSSL, IdBaseComponent, IdComponent,
IdCustomTCPServer, IdTCPServer, Vcl.StdCtrls, IdIOHandler, IdIOHandlerSocket,
IdIOHandlerStack, IdTCPConnection, IdTCPClient;
type
TForm1 = class(TForm)
Server: TIdTCPServer;
Client: TIdTCPClient;
cSSL: TIdSSLIOHandlerSocketOpenSSL;
Button1: TButton;
SSL: TIdServerIOHandlerSSLOpenSSL;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ServerExecute(AContext: TIdContext);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const usessl = false;
procedure TForm1.Button1Click(Sender: TObject);
begin
Client.Connect;
Client.IOHandler.WriteLn('test');
Client.Disconnect;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Server:= TIdTCPServer.Create;
Server.DefaultPort := 443;
Client:= TIdTCPClient.Create;
Client.Host := 'Localhost';
Client.Port := 443;
Server.OnExecute := ServerExecute;
if UseSSL then
begin
cSSL:= TIdSSLIOHandlerSocketOpenSSL.Create;
SSL:= TIdServerIOHandlerSSLOpenSSL.Create;
SSL.SSLOptions.Mode := sslmServer;
SSL.SSLOptions.VerifyMode := [];
SSL.SSLOptions.VerifyDepth := 0;
SSL.SSLOptions.SSLVersions := [sslvSSLv2..sslvTLSv1_2];
TIdSSLIOHandlerSocketBase(cSSL).PassThrough := false;
cSSL.SSLOptions.Mode := sslmClient;
cSSL.SSLOptions.VerifyMode := [];
cSSL.SSLOptions.VerifyDepth := 0;
cSSL.SSLOptions.SSLVersions := [sslvSSLv2..sslvTLSv1_2]; // Avoid using SSL}
Server.IOHandler := SSL; // TIdServerIOHandlerSSLOpenSSL
Client.IOHandler := cSSL; // TIdSSLIOHandlerSocketOpenSSL
end;
Server.Active := true;
end;
procedure TForm1.ServerExecute(AContext: TIdContext);
var s : string;
begin
s := aContext.Connection.IOHandler.Alldata;
s := s;
end;
end.