Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Indy10 CompressionIntercept problems


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Feb 25, 2016 8:59 AM Last Post By: Jay Dee
Jay Dee

Posts: 44
Registered: 11/22/10
Indy10 CompressionIntercept problems  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2015 8:46 AM
Hi there everyone,

I'm having problems implementing data compression between a TCPServer & a TCPClient. When I switch compression on, I get no response on the client-side when I try to connect to the server.

My code is listed below:

I use a compiler define to activate compression

{$DEFINE COMPRESS_DATA}

Client side code

a) Form OnCreate

  {$IFDEF COMPRESS_DATA}
  with Client do
  begin
    Intercept := TIdCompressionIntercept.Create(nil);   
    TIdCompressionIntercept(Intercept).CompressionLevel := 9;     
  end;
  {$ENDIF}


b) Form OnDestroy
  {$IFDEF COMPRESS_DATA}
  // Déconnexion d'un client au serveur : libération du compresseur de données
  with Client do
  begin
    if Assigned(Intercept) then   
    begin
       Intercept.Free;            .
       Intercept := nil;
    end;
  end;
  {$ENDIF}


Server side code

a) Server OnConnect

  {$IFDEF COMPRESS_DATA}
  with (AContext.Connection) do
  begin
    Intercept := TIdCompressionIntercept.Create(nil);         // Créer le "décompresseur"
    TIdCompressionIntercept(Intercept).CompressionLevel := 9; // Niveau de compression
    //Intercept := TIdServerCompressionIntercept.Create(nil);             // Créer le "décompresseur"
    //TIdServerCompressionIntercept(Intercept).CompressionLevel := 9;     // Niveau de compression
  end;
  {$ENDIF}


b) Server Disconnect

  {$IFDEF COMPRESS_DATA}
  // Déconnexion d'un client au serveur : libération du compresseur de données
  with (AContext.Connection) do
  begin
    if Assigned(Intercept) then   // Assigné ?
    begin
       Intercept.Free;            // on libère...
       Intercept := nil;
    end;
  end;
  {$ENDIF}


Thanks for your kind assistance.

Jay Dee

Edited by: Jay Dee on Dec 21, 2015 5:47 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Indy10 CompressionIntercept problems [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 21, 2015 12:25 PM   in response to: Jay Dee in response to: Jay Dee
Jay wrote:

I'm having problems implementing data compression between a TCPServer
& a TCPClient. When I switch compression on, I get no response on the
client-side when I try to connect to the server.

You have shown the code that is enabling compression (which is technically
correct as shown), but you have not show any code that is trying to send
data between the client and server after compression has been enabled.

I use a compiler define to activate compression

Why? If you have a mismatch where the client defines it and the server does
not, or vice versa, they won't be able to talk to each other. Either compression
should always be enabled as part of your protocol, or the client and server
should negotiate with each other at runtime over whether compression can
be used or not.

a) Form OnCreate

Is there a reason you are creating the TIdCompressionIntercept object dynamically
and not simply dropping it on your Form at design-time?

b) Form OnDestroy

If you give the Intercept an Owner, you can get rid of all that code.

a) Server OnConnect

Though technically this code will work as shown, you can alternative assign
a TIdServerCompressionIntercept to the TIdTCPServer.Intercept property (not
the TIdContext.Connection.Intercept property), and it will automatically
create and assign a new TIdCompressionIntercept for each accepted client
connection.

b) Server Disconnect

TIdTCPServer automatically frees an assigned Intercept when the client disconnects,
so you do not need to do it manually.

--
Remy Lebeau (TeamB)
Jay Dee

Posts: 44
Registered: 11/22/10
Re: Indy10 CompressionIntercept problems [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 25, 2016 8:47 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Sorry for the late, late, late reply. I had forgotten about this because I later decided not to use compression in this particular project.

I'll revisit it some other time.

JayDee

Remy Lebeau (TeamB) wrote:
Jay wrote:

I'm having problems implementing data compression between a TCPServer
& a TCPClient. When I switch compression on, I get no response on the
client-side when I try to connect to the server.

You have shown the code that is enabling compression (which is technically
correct as shown), but you have not show any code that is trying to send
data between the client and server after compression has been enabled.

I use a compiler define to activate compression

Why? If you have a mismatch where the client defines it and the server does
not, or vice versa, they won't be able to talk to each other. Either compression
should always be enabled as part of your protocol, or the client and server
should negotiate with each other at runtime over whether compression can
be used or not.

a) Form OnCreate

Is there a reason you are creating the TIdCompressionIntercept object dynamically
and not simply dropping it on your Form at design-time?

b) Form OnDestroy

If you give the Intercept an Owner, you can get rid of all that code.

a) Server OnConnect

Though technically this code will work as shown, you can alternative assign
a TIdServerCompressionIntercept to the TIdTCPServer.Intercept property (not
the TIdContext.Connection.Intercept property), and it will automatically
create and assign a new TIdCompressionIntercept for each accepted client
connection.

b) Server Disconnect

TIdTCPServer automatically frees an assigned Intercept when the client disconnects,
so you do not need to do it manually.

--
Remy Lebeau (TeamB)

Edited by: Jay Dee on Feb 25, 2016 5:59 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02