I don't see an Execute method. Only the code in that method is threaded! You create your components in the constructor of the thread. This is main thread context (because you call it from within the main thread). So you have to create it all in the Execute method and put there a message pump.

Met vriendelijke groeten,
Wilfried

Op 23-09-15 om 12:50 schreef Boris JURČAK, Kostra d.o.o.:
Hi

Thanks for fast respond ....

I put code (for logging) on event OnBgException ...

Result:
[12:21:19.814] Logger:12:21:19:770 State = httpNotConnected
[12:21:19.815] Logger:12:21:19:770 Login "www..."
[12:21:19.816] Logger:12:21:19:773 State = httpDnsLookup
[12:21:19.817] Logger:12:21:19:817 State = httpDnsLookupDone
[12:21:19.819] Logger:12:21:19:819 connect to "IP"/443
[12:21:19.822] Logger:12:21:19:822 00AA6F20 Socket handle created 968
[12:21:19.825] Logger:12:21:19:824 TWSocket will connect to "IP":443
[12:21:19.843] Logger:12:21:19:843 SessionConnected
[12:21:19.844] Logger:12:21:19:843 00AA6F20 TCustomSslWSocket.Do_FD_WRITE 968 *[12:21:21.159] TMyHTTPSCli.SslHttpCliBgException=Access violation at address 5D2571E4 in module 'SSLEAY32.DLL'. Read of address 00000034 (this is event OnBgException)*
[12:21:21.162] Logger:12:21:21:162 State = httpAborting
[12:21:21.164] Logger:12:21:21:164 00AA6F20 *CloseCalled 968
[12:21:21.167] Logger:12:21:21:167 00AA6F20 TCustomWSocket.Shutdown 1 968
[12:21:21.170] Logger:12:21:21:170 SessionClosed Error: 0
[12:21:21.174] Logger:12:21:21:174 State = httpReady

*My code:
*....
type THttpsThread = class(TThread)*
...

*constructor THttpsThread.Create;
begin
  inherited Create(False);

  IcsLogger := TIcsLogger.Create(nil);
  with IcsLogger do
  begin
    Name := 'IcsLogger1';
    TimeStampFormatString := 'hh:nn:ss:zzz';
    TimeStampSeparator := ' ';
    LogFileOption := lfoOverwrite;
    LogFileEncoding := lfeUtf8;
    LogFileName := 'Debug_Out_HttpsTst.txt';
LogOptions := [loDestEvent, loDestFile, loDestOutDebug, loAddStamp, loWsockErr, loWsockInfo, loWsockDump, loSslErr, loSslInfo, loSslDump, loProtSpecErr,
                   loProtSpecInfo, loProtSpecDump];
    OnIcsLogEvent := IcsLoggerIcsLogEvent;
  end;

  SslContextCli := TSslContext.Create(nil);
  with SslContextCli do
  begin
    Name := 'SslContext';
    IcsLogger := IcsLogger;
    SslCipherList := 'ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH';
    SslCaFile:='';
    SslCAFile:='';
    SslCRLFile:='';
    SslCRLPath:='';
    SslDefaultSessionIDContext:='';
    SslDHParamFile:='';
    SslECDHMethod := sslECDH_P256;
SslOptions := [sslOpt_MICROSOFT_SESS_ID_BUG, sslOpt_NETSCAPE_CHALLENGE_BUG, sslOpt_NETSCAPE_REUSE_CIPHER_CHANGE_BUG, sslOpt_MICROSOFT_BIG_SSLV3_BUFFER, sslOpt_SSLEAY_080_CLIENT_DH_BUG, sslOpt_TLS_D5_BUG, sslOpt_TLS_BLOCK_PADDING_BUG, sslOpt_TLS_ROLLBACK_BUG, sslOpt_NO_SSLv2, sslOpt_NO_SSLv3, sslOpt_NETSCAPE_CA_DN_BUG,
                  sslOpt_NETSCAPE_DEMO_CIPHER_CHANGE_BUG];
    SslPassPhrase := 'password';
    SslCertFile := "Path to pem cert file";
    SslPrivKeyFile := "Path to pem cert file";
SslSessionCacheModes := [sslSESS_CACHE_CLIENT, sslSESS_CACHE_NO_INTERNAL_LOOKUP, sslSESS_CACHE_NO_INTERNAL_STORE];
    SslSessionCacheSize := 20480;
    SslSessionTimeout := 300;
    SslVerifyDepth := 9;
    SslVerifyPeer := False;
    SslVerifyPeerModes := [SslVerifyMode_PEER];
    SslVerifyFlags := [];
    SslVersionMethod := sslBestVer_CLIENT;
    AutoEnableBuiltinEngines := False;
  end;

  SslAvlSessionCache := TSslAvlSessionCache.Create(nil);

  with SslAvlSessionCache do
  begin
    Name := 'SslAvlSessionCache1';
    IcsLogger := IcsLogger;
    IdleTimeout := 30;
    FlushInterval := 10000;
    MaxCacheSize := 1000;
  end;

  SslHttpCli := TSslHttpCli.Create(nil);
  FClientCerts := nil;
  SslHttpCli.CtrlSocket.OnBgException := BackgroundException;
  with SslHttpCli do
  begin
    Name := 'SslHttpCli';
    LocalAddr := '0.0.0.0';
    LocalAddr6 := '::';
    ProxyPort := '80';
    Agent := 'Mozilla/4.0 (compatible; ICS; MSIE 4.0)';
    Accept := '';
    ProxyConnection := 'Keep-Alive';
    NoCache := True;
    ContentTypePost := 'application/x-www-form-urlencoded';
    RequestVer := '1.0';
    FollowRelocation := False;
    LocationChangeMaxCount := 5;
    ServerAuth := httpAuthNone;
    ProxyAuth := httpAuthNone;
    BandwidthLimit := 10000;
    BandwidthSampling := 1000;
    Options := [];
    IcsLogger := IcsLogger;
    Timeout := 30;
    SocksLevel := '5';
    OnDocBegin := SslHttpCliDocBegin;
    OnRequestDone := SslHttpCliRequestDone;
    OnSendBegin := SslHttpCliSendBegin;
    OnSendEnd := SslHttpCliSendEnd;
    OnSslCliCertRequest := SslHttpCliSslCliCertRequest;
    OnSslCliGetSession := SslHttpCliSslCliGetSession;
    OnSslCliNewSession := SslHttpCliSslCliNewSession;
    OnSslHandshakeDone := SslHttpCliSslHandshakeDone;
    OnSslVerifyPeer := SslHttpCliSslVerifyPeer;
  end;

  FreeOnTerminate:=True;
end;

procedure TMyHTTPSCli.PrepareCli;
const
  SocksLevelValues : array [0..2] of String = ('5', '4A', '4');
  SslVersions : array [0..5] of TSslVersionMethod =
(sslBestVer_CLIENT,sslV2_CLIENT,sslV3_CLIENT,sslTLS_V1_CLIENT,sslTLS_V1_1_CLIENT,sslTLS_V1_2_CLIENT); { V8.01 }
var
  cli:TSslHttpCli;
begin
  cli:=SslHttpCli;
  cli.SslContext:=nil;
  cli.SslContext:=SslContextCli;
  cli.ContentTypePost:= 'text/xml';
  Cli.SslAcceptableHosts.Clear;
  Cli.SslAcceptableHosts.Add('www ...');
  cli.Accept:='text/xml';
  cli.AcceptLanguage:='en';
  cli.Timeout:=30;
  cli.ProxyConnection:='';
  cli.Username:='';
  cli.Password:='';
  cli.ModifiedSince := 0;
  cli.SocksServer := '';
  cli.SocksPort   := '';
  cli.SocksLevel  := '5';
  cli.RequestVer  := '1.0';

  cli.URL                    := 'https:// .......';

  cli.SslContext.SslVerifyPeer       := false;
  cli.SslPassPhrase := 'password';
  cli.SslCertFile := "Path to pem cert file";
  cli.SslPrivKeyFile := "Path to pem cert file";

  cli.SslContext.SslVersionMethod    := sslBestVer_CLIENT;   { V8.01 }
cli.SslContext.SslCipherList := 'ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH'; { V8.01 }
  cli.SslContext.SslDHParamFile      := '';                     { V8.01 }

{ V8.01 - set options to force a single SSL/TLS version, not normally a good idea,
  but seems only reliable way of forcing use of a specific version }
cli.SslContext.SslOptions := cli.SslContext.SslOptions + [sslOpt_NO_SSLv2, sslOpt_NO_SSLv3, sslOpt_NO_TLSv1, sslOpt_NO_TLSv1_1, sslOpt_NO_TLSv1_2];
  if cli.SslContext.SslVersionMethod = sslV2_CLIENT then
cli.SslContext.SslOptions := cli.SslContext.SslOptions - [sslOpt_NO_SSLv2]
  else if cli.SslContext.SslVersionMethod = sslV3_CLIENT then
cli.SslContext.SslOptions := cli.SslContext.SslOptions - [sslOpt_NO_SSLv3]
  else if cli.SslContext.SslVersionMethod = sslTLS_V1_CLIENT then
cli.SslContext.SslOptions := cli.SslContext.SslOptions - [sslOpt_NO_TLSv1]
  else if cli.SslContext.SslVersionMethod = sslTLS_V1_1_CLIENT then
cli.SslContext.SslOptions := cli.SslContext.SslOptions - [sslOpt_NO_TLSv1_1]
  else if cli.SslContext.SslVersionMethod = sslTLS_V1_2_CLIENT then
cli.SslContext.SslOptions := cli.SslContext.SslOptions - [sslOpt_NO_TLSv1_2]
  else
cli.SslContext.SslOptions := cli.SslContext.SslOptions - [sslOpt_NO_SSLv2, sslOpt_NO_SSLv3, sslOpt_NO_TLSv1, sslOpt_NO_TLSv1_1, sslOpt_NO_TLSv1_2];

  try
cli.SslContext.InitContext; { V8.01 get any error now before making request }
  except
    on E:Exception do begin
        ....
        Exit;
    end;
  end;
end;

function TMyHTTPSCli.PostData(sData:string):boolean;
var
  Cli:TSslHttpCli;
begin
  try
    try
      Cli:=SslHttpCli;

      Cli.CtrlSocket.ResetSSL;
      Cli.SslContext.DeInitContext;

      Cli.SendStream:= TStringStream.Create(sData);
      PrepareCliTelekom(provider, val);


      if not Cli.SslContext.IsCtxInitialized then Exit;  { V8.01 }
      DispMessage('HTTPS Connecting...',DISP_SMS, clBlue);

      PrepareCli;
      Cli.Post;

    except
      on E:Exception do begin
        ...
        Exit;
      end;
    end;
  finally
    if Assigned(Cli.SendStream) then begin
      Cli.SendStream.Free;
      Cli.SendStream := nil;
    end;
    if Assigned(Cli.RcvdStream) then begin
      Cli.RcvdStream.Free;
      Cli.RcvdStream := nil;
    end;
  end;
end;

When I put this code on the Form (the form create all components), all work ok.

Where I made mistake?

Regards
Boris


Signature
------------------------------------------------------------------------

Angus Robertson - Magenta Systems Ltd je 9/23/2015 ob 11:35 AM napisal:
How can I use TSslHttpCli in multi threading app.
There are no errors in the log you posted, only an abort after connect, you'll need
to debug your code.

Angus



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to