Thank you both very much for your answers. I chose to implement it the way mghie described it - by implementing a custom interceptor class for my connections. Just for those interested in the solution, i will provide some source code here:
type
TCountTrafficInterceptor = class (TIdConnectionIntercept)
public
type TIntPointer = ^Longint;
private
FTraffic : TIntPointer;
public
constructor Create (TrafficVar : TIntPointer);
procedure Send (var ABuffer : TIdBytes); override;
procedure Receive (var ABuffer : TIdBytes); override;
end;
constructor TCountTrafficInterceptor.Create (TrafficVar : TIntPointer);
begin
FTraffic := TrafficVar;
end;
procedure TCountTrafficInterceptor.Send (var ABuffer : TIdBytes);
begin
inherited Send (ABuffer);
FTraffic^ := FTraffic^ + Length (ABuffer);
end;
procedure TCountTrafficInterceptor.Receive (var ABuffer : TIdBytes);
begin
inherited Receive (ABuffer);
FTraffic^ := FTraffic^ + Length (ABuffer);
end;
And in the OnConnect method of the TIdTCPCmdServer:
AContext.Connection.IOHandler.Intercept :=
TCountTrafficInterceptor.Create (@FNetworkTraffic);
Works great, just the kind of solution I was looking for. Thanks again for your answers.
Btw: How can I use the (at) sign in my posts? I always get a block quote when I try to type it...