I'm developing a TCP Client-Server application.
I'm trying to get the compressed size of the packets I send to the client so I can compare that size with the uncompressed data size and get statistics about the compression ratio obtained.
On the Client side. I can get that information comparing the size of the sent/received data with the size I get from the OnSend/OnReceive events of TIdCompressionIntercept
. Just getting the length of the ABuffer
parameter of those event handlers.
But, on the Server side, the TIdServerCompressionIntercept does't have those events to hook.
So the question. How can I get the compressed size of the packets sent/received by the server, so I can compare those sizes with the raw data size of those packets?
Thanks.
Client side code sample:
var
FRawSentSize ,
FComrpessedSentSize ,
FRawReceivedSize ,
FCompressedReceivedSize : UInt64;
function TFrom1.SendAndReceive( const ToSend: String ): String;
begin
TCPClient.IOHandler.WriteLn( ToSend );
Inc( FRawSentSize, Length( ToSend ) );
Result := TCPClient.IOHandler.ReadLn;
Inc( FRawReceivedSize, Length( Result ) );
end;
function TForm1.CompressorSend( ASender: TIdConnectionIntercept; var ABuffer: TIdBytes );
begin
Inc( FComrpessedSentSize, Length( ABuffer ) );
end;
function TForm1.CompressorReceive( ASender: TIdConnectionIntercept; var ABuffer: TIdBytes );
begin
Inc( FCompressedReceivedSize, Length( ABuffer ) );
end;
TIdServerCompressionIntercept
is not the intercept that does the actual work, so that is why it has no events.
When a new client connects to the server, TIdServerCompressionIntercept
will create a TIdCompressionIntercept
object that gets assigned to the AContext.Connection.IOHandler.Intercept
property. That object does the actual work, just like in the client-side code. Your server's OnConnect
or OnExecute
event handler can programmably assign handlers to that object's events as needed.