I'm using a TIdTCPCmdServer to handle all communication with client applications. I would like my server to log all kind of stuff including network traffic. Is there any easy or clever way to see how much bytes the TCPCmdServer actually received and sent? I can only think of code like
ASender.SendReply;
Inc (FTraffic, Sizeof (ASender.NormalReply.Code) +
Sizeof (Char) * ASender.NormalReply.Text.Length));
which is extremely ugly in my opinion because these traffic updates would be spreaded out all over my code and are fairly complicated as well.
Any suggestions?
Thanks for your help.
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:
And in the OnConnect method of the TIdTCPCmdServer:
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...
Look into the intercept classes of Indy. You should be able to create a custom intercept class that overrides the Receive() and Send() methods, and in addition to calling the methods of the base class implements your traffic calculation. There are already intercept classes to do logging, you would connect your custom class in the same way.
The documentation of TIdConnectionIntercept should be a good starting point. There is also a very simple example here on how to create and connect an intercept at runtime.
Wrap
TCPCmdServer
into class that logs traffic.You can derive your class from TCPCmdServer and override send and receive methods if they are virtual.
Something like:
If they aren't virtual, then create new class that instantiates TCPCmdServer and expose required methods and properties.