Monitor incoming traffic


Is it possible to monitor all incoming traffic on an specific port? Even if a request doesn’t match a valid method? This would be helpful to detect external attacks or just to log messages from allowed consumers for troubleshooting purpouses.

I’m using TROIndyHttpServer with TROBinMessage/TROJSONMessage + Dispatchers and TROHttpApiDispatcher + TROHttpApiSimpleAuthenticationManager.

Relating to HTTPAPI it would be important to log Command, Full Path and especially the Body. Is there any possibilty?

Thanks and best regards,


you can log all incoming requests in Server.OnReadFromStream event.

another way - use code snippet from Using OnCustomResponseEvent in a ROSDK Server.
Note: the OnCustomResponseEvent handles only unknown requests.

Okay, thanks! But at this part of code I can’t map the incoming request with it’s requesting client, right?


In OnCustomResponseEvent event you can get ClientAddress from IROHTTPTransport interface

Yes I know. But in Server.OnReadFromStream event there is no reference.


You can use also the Message.OnReadFromStream event

But there is no IROHTTPTransport given?

you can identity client by Message.ClientID

And from where can I get the Message.ClientID?

AFAIK the procedure is defined as
procedure OnReadFromStream(aStream: TStream)

you are right, TROMessage is now thread-safe so this event just include incoming data.

use OnCustomResponseEvent event.
here you can log everything.

simple usage:

procedure TServerMainForm.ROServerCustomResponseEvent(
  const aTransport: IROHTTPTransport; const aRequestStream,
  aResponseStream: TStream; const aResponse: IROHTTPResponse;
  var aHandled: Boolean);
  lMessage:  IROMessage;
  op: TROResponseOptions;
  // handle all requests equal to 'Bin':
  if AnsiSameText(aTransport.PathInfo, '/Bin') then begin  // "Bin" shouldn't be defined in Server.Dispathers !!!

    // log info & data
    MyLog(aTransport, aRequestStream);

    // Invoke service method 
    lMessage:= (ROBinMessage as IROMessageCloneable).Clone;

    aHandled := True;