(* Collection of code snippets by Arne Vajhøj *)
(* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) *)
program SecureBinClient;

uses
  IdTCPClient, IdSSLOpenSSL;

const
  HOST = 'localhost';
  PORT = 12345;

var
  ssl : TIdSSLIOHandlerSocketOpenSSL;
  cli : TIdTCPClient;
  v, v2 : string;
  a, b, c, len : integer;

begin
  (* open connection *)
  ssl := TIdSSLIOHandlerSocketOpenSSL.Create;
  ssl.sslOptions.VerifyMode := [];
  ssl.sslOptions.VerifyDepth := 0;
  ssl.sslOptions.SSLVersions := [sslvTLSv1_2];
  ssl.sslOptions.Mode := sslmClient;
  cli := TIdTCPClient.Create;
  cli.IOHandler := ssl;
  cli.Connect(HOST, PORT);
  (* send a and b *)
  a := 123;
  b := 456;
  cli.Socket.Write(a, true);
  cli.Socket.Write(b, true);
  (* receive c and print *)
  c := cli.Socket.ReadInt32(true);
  writeln(c);
  (* send v *)
  v := 'ABC';
  cli.Socket.Write(Byte(length(v)));
  cli.Socket.Write(v);
  (* received v2 and print *)
  len := cli.Socket.ReadByte;
  v2 := cli.Socket.ReadString(len);
  writeln(v2);
  (* close connection *)
  cli.Disconnect;
  cli.Free;
end.

