• Page:
  • 1

TOPIC: Linux TIdTCPServer with OpenSSL and compression

Linux TIdTCPServer with OpenSSL and compression 4 months 1 week ago #14317

I am testing TIdTCPServer with Linux. The clients are using windows. I have got two problems with OpenSSL and compression. It works fine with Windows. It also works fine if OpenSSL and compression are inactive.

1. When I start the server with OpenSSL (compression inactive) it works. But when I try to stop the server (Active := False), it hangs up.
2. When I start the server with compression (OpenSSL inactive), a Windows client is not able to connect.

unit TCPServer ;

interface

uses
  IdComponent,
  IdContext,
  IdCustomTCPServer,
  IdGlobal,
  IdSocketHandle,
  IdSSL,
  IdStack,
  IdTCPServer,
  System.Classes,
  System.Hash,
  System.SysUtils,
  IdSSLOpenSSL,
  IdCompressionIntercept ;

// *** TTCPServer **************************************************************
type
  TTCPServer = class(TIdTCPServer)

  private
    { Private-Deklarationen }
    FCompression : TIdServerCompressionIntercept ;
    FTLS         : TIdServerIOHandlerSSLOpenSSL ;

    procedure EventOnGetPassword
    ( var iPassword : String ) ;

    procedure EventOnContextCreated
    ( iContext : TIdContext ) ;
    procedure EventOnExecute
    ( iContext : TIdContext ) ;

  protected
    { Protected-Deklarationen }

  public
    { Public-Deklarationen }
    constructor Create
    ( const iOwner : TComponent ) ; overload ;
    destructor  Destroy ; override ;

  published
    { Published-Deklarationen }
  end ;

implementation

// *** Start Create ************************************************************
// *****************************************************************************
constructor TTCPServer.Create
( const iOwner : TComponent ) ;
var
iBinding : TIdSocketHandle ;
begin
{ Inherited }
inherited Create(iOwner) ;

{ Properties }
ReuseSocket := rsTrue ;
{ Compression }
FCompression                  := TIdServerCompressionIntercept.Create(Self) ;
FCompression.CompressionLevel := 9 ;
{ TLS }
FTLS               := TIdServerIOHandlerSSLOpenSSL.Create(Self) ;
FTLS.OnGetPassword := EventOnGetPassword ;
{ Events }
OnContextCreated := EventOnContextCreated ;
OnExecute        := EventOnExecute ;

{ Bind IP }
iBinding             := Bindings.Add ;
iBinding.Port        := 8700 ;
iBinding.ReuseSocket := rsTrue ;
iBinding.IPVersion   := Id_IPv4 ;
iBinding.IP          := '127.0.0.1' ;
{ TLS files linux }
FTLS.SSLOptions.KeyFile  := '/home/thomas/Delphi/sample.key' ;
FTLS.SSLOptions.CertFile := '/home/thomas/Delphi/sample.crt' ;
{ Intercept and IO }
// Intercept := FCompression ;
IOHandler := FTLS ;
end ;
// *** End Create **************************************************************
// *****************************************************************************


// *** Start Destroy ***********************************************************
// *****************************************************************************
destructor TTCPServer.Destroy ;
begin
{ Eigenschaften }
FCompression.DisposeOf ;
FTLS.DisposeOf ;
{ Ererbte Eigenschaften }
inherited Destroy ;
end ;
// *** End Destroy *************************************************************
// *****************************************************************************

// -----------------------------------------------------------------------------

// *** Start EventOnGetPassword ************************************************
// *****************************************************************************
procedure TTCPServer.EventOnGetPassword
( var iPassword : String ) ;
begin
{ Set password }
iPassword := 'aaaa' ;
end ;
// *** End EventOnGetPassword **************************************************
// *****************************************************************************

// -----------------------------------------------------------------------------

// *** Start EventOnContextCreated *********************************************
// *****************************************************************************
procedure TTCPServer.EventOnContextCreated
( iContext : TIdContext ) ;
begin
{ Use TLS }
if iContext.Connection.IOHandler is TIdSSLIOHandlerSocketBase then
  TIdSSLIOHandlerSocketBase(iContext.Connection.IOHandler).PassThrough := False ;
end ;
// *** End EventOnContextCreated ***********************************************
// *****************************************************************************


// *** Start EventOnExecute ****************************************************
// *****************************************************************************
procedure TTCPServer.EventOnExecute
( iContext : TIdContext ) ;
var
iInput : TStringList ;
begin
{ Create list }
iInput := TStringList.Create ;

{ Get data }
iContext.Connection.IOHandler.ReadStrings(iInput,-1,IndyTextEncoding_UTF8) ;
{ Show data }
WriteLn(iInput.Text) ;

{ Disconnect client}
iContext.Connection.Disconnect ;
{ Prevent 100% cpu }
if iContext.Connection.IOHandler.InputBufferIsEmpty = True then
  iContext.Connection.IOHandler.CheckForDataOnSource(10) ;

{ Delete list }
iInput.DisposeOf ;
end ;
// *** End EventOnExecute ******************************************************
// *****************************************************************************
end.
Attachments:

Please Log in or Create an account to join the conversation.

Linux TIdTCPServer with OpenSSL and compression 4 months 5 days ago #14375

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: April Anne