Strange behaviour with Compression Intercept

Giganews Newsgroups
Subject: Strange behaviour with Compression Intercept
Posted by:  Hayro A. Zúñiga Gómez (naya…@gmail.com)
Date: Sat, 9 Jun 2007

Hello,

  I had set compression on my class server and class client as follows:

DEMO SERVER
procedure TfServerMain.IdTCPServer1Connect(AContext: TIdContext);
begin
    AContext.Connection.Intercept:=nil;
    AContext.Connection.IOHandler.Intercept:=nil;
    AContext.Connection.IOHandler.Intercept:=TIdCompressionIntercept.Create(nil);
    TIdCompressionIntercept(AContext.Connection.IOHandler.Intercept).CompressionLevel:=9;
end;

procedure TfServerMain.IdTCPServer1Disconnect(AContext: TIdContext);
begin
    if assigned(AContext.Connection.IOHandler.Intercept) then
    begin
        AContext.Connection.IOHandler.Intercept.free;
        AContext.Connection.IOHandler.Intercept:=nil;
    end;
end;

Why I can not use:
  private to object
    IdCompressionIntercept1 : TIdServerCompressionIntercept;

On Formcreate
    IdTCPServer1.Intercept:=TIdServerCompressionIntercept.Create(nil);
    TIdServerCompressionIntercept(IdTCPServer1.Intercept).CompressionLevel:=9;
On FormDestroy
    IdTCPServer1.Intercept.Free;

DEMO CLIENT
private in object
TCPClientFileThread    : TIdTCPClient;
{}
procedure TIndyInaThread.CMD_CONNECT;
begin
    try
        TCPClientFileThread .Connect;

        TCPClientFileThread
..IOHandler.Intercept:=TIdCompressionIntercept.Create(nil);
        TIdCompressionIntercept(TCPClientFileThread
..IOHandler.Intercept).CompressionLevel:=9;

        TCPClientFileThread .IOHandler.LargeStream := True;
    except
    end;
end;
{}
procedure TIndyInaThread.CMD_DISCONNECT;
begin
    try
        TCPClientFileThread .Disconnect;

        if assigned(TCPClientInsideThread.IOHandler.Intercept) then
        begin
            TCPClientFileThread .IOHandler.Intercept.free;
            TCPClientFileThread .IOHandler.Intercept:=nil;
        end;

    except
    end;
end;

Hello Remy, if you can see this inconvenient, you advise me on another issue
not related:
"Simple attach a compression Intercept to the IOHandler's Intercept
property on both sides of the connection, and then set the Level to
the same value"

I did steps well?

THE PROBLEM

On server, workcount did not correspond to compresses bytes counts,  if it's
would not be compressed at all, except that I have set breakpoints in
TIdCompressionIntercept.Receive and TIdCompressionIntercept.Receive and they
are active on any transmision between client and server.

On Client this problem did not happen.

Visual effect on both progress bar(client and server) is not correct, main
problem it's on client cause user see that when progress bar its at 15% for
example it has finished, while on server user can see all progress until its
finished. File is transmited correctly.

For Example onwork of client workacount report 4737 first chunk transmited
of a text file, but on Server it reports 32768. OnWorkBegin reports
AWorkCountMax same value on both sides.

On Client
procedure TIndyFileThread.TCPClientInsideThreadWork(ASender: TObject;
AWorkMode: TWorkMode; AWorkCount: int64);
On Server
procedure TClientSpecificData.TCPClientInsideThreadWork(ASender: TObject;
AWorkMode: TWorkMode; AWorkCount: int64);
where TClientSpecificData is a descendent from TObject that it's assigned on
every connection on IdTCPServer1Connect as follows:
    AContext.Data := TClientSpecificData.CreateWithSettings(ID_);
where AContext it's a descendent from TIdContext

When I use a zipped file workcount on both sides arrives ok.
What I want to know if server is decompressing OK.

Do I need to use zlib1.dll or use another zlib sources, I have seen Indy has
zlibEx 1.2.3.

Notes:--------------------------------------------------
1. I am not using TIdServerCompressionIntercept on server side cause when I
set
    AContext.Connection.IOHandler.Intercept:=TIdServerCompressionIntercept.Create(nil);
  are not compatible.

I had seen briefly that TIdServerCompressionIntercept is like an
TIdCompressionIntercept, except that on every connection it iniatialice an
TIdCompressionIntercept and assign one.

2. LargeStream is set to true on both sides. (Anyway it's just do a typecast
of int or int64 of ASize)

Thanks in advance for your help.

Replies