# Monitor incoming traffic

**URL:** https://talk.remobjects.com/t/monitor-incoming-traffic/21263
**Category:** Remoting SDK
**Created:** [January 30, 2020, 12:42pm UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263 "2020-01-30T12:42:14Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Benjamin\_Keffer\_EP](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Benjamin\_Keffer\_EP](https://talk.remobjects.com/u/Benjamin_Keffer_EP)
#### Post date: [January 30, 2020, 12:42pm UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/1 "2020-01-30T12:42:14Z")

</div>

Hey,

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,  
Benjamin

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [January 30, 2020, 1:09pm UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/2 "2020-01-30T13:09:23Z")

</div>

Hi,

you can log all incoming requests in Server.[OnReadFromStream](https://docs.remotingsdk.com/API/Delphi/Classes/TROIndyHTTPServer/#OnReadFromStream) event.

another way - use code snippet from [Using OnCustomResponseEvent in a ROSDK Server](https://talk.remobjects.com/t/using-oncustomresponseevent-in-a-rosdk-server/6767).  
Note: the [OnCustomResponseEvent](https://docs.remotingsdk.com/API/Delphi/Classes/TROBaseHTTPServer/#OnCustomResponseEvent) handles only **unknown** requests.

---

<div class="post-metadata">

### Author: ![Benjamin\_Keffer\_EP](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Benjamin\_Keffer\_EP](https://talk.remobjects.com/u/Benjamin_Keffer_EP)
#### Post date: [January 31, 2020, 9:31am UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/3 "2020-01-31T09:31:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 3, 2020, 8:50am UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/4 "2020-02-03T08:50:47Z")

</div>

Hi,

In `OnCustomResponseEvent` event you can get [ClientAddress](https://docs.remotingsdk.com/API/Delphi/Interfaces/IROHTTPTransport/#ClientAddress) from [IROHTTPTransport](https://docs.remotingsdk.com/API/Delphi/Interfaces/IROHTTPTransport/) interface

---

<div class="post-metadata">

### Author: ![Benjamin\_Keffer\_EP](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Benjamin\_Keffer\_EP](https://talk.remobjects.com/u/Benjamin_Keffer_EP)
#### Post date: [February 3, 2020, 9:11am UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/5 "2020-02-03T09:11:09Z")

</div>

> [@EvgenyK](#):
>
> Server.[OnReadFromStream](https://docs.remotingsdk.com/API/Delphi/Classes/TROIndyHTTPServer/#OnReadFromStream)

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

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 3, 2020, 9:13am UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/6 "2020-02-03T09:13:53Z")

</div>

Hi,

You can use also the [Message.OnReadFromStream](https://docs.remotingsdk.com/API/Delphi/Classes/TROBinMessage/#OnReadFromStream) event

---

<div class="post-metadata">

### Author: ![Benjamin\_Keffer\_EP](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Benjamin\_Keffer\_EP](https://talk.remobjects.com/u/Benjamin_Keffer_EP)
#### Post date: [February 3, 2020, 9:14am UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/7 "2020-02-03T09:14:42Z")

</div>

But there is no [IROHTTPTransport](https://docs.remotingsdk.com/API/Delphi/Interfaces/IROHTTPTransport/) given?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 3, 2020, 9:16am UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/8 "2020-02-03T09:16:25Z")

</div>

you can identity client by [Message.ClientID](https://docs.remotingsdk.com/API/Delphi/Classes/TROBinMessage/#ClientID)

---

<div class="post-metadata">

### Author: ![Benjamin\_Keffer\_EP](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/b/b782af/32.png) [@Benjamin\_Keffer\_EP](https://talk.remobjects.com/u/Benjamin_Keffer_EP)
#### Post date: [February 18, 2020, 2:32pm UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/9 "2020-02-18T14:32:00Z")

</div>

And from where can I get the Message.ClientID?

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

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 18, 2020, 3:10pm UTC](https://talk.remobjects.com/t/monitor-incoming-traffic/21263/10 "2020-02-18T15:10:07Z")

</div>

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

use [OnCustomResponseEvent](https://docs.remotingsdk.com/API/Delphi/Classes/TROBaseHTTPServer/#OnCustomResponseEvent) event.  
here you can log everything.

simple usage:

```auto
procedure TServerMainForm.ROServerCustomResponseEvent(
  const aTransport: IROHTTPTransport; const aRequestStream,
  aResponseStream: TStream; const aResponse: IROHTTPResponse;
  var aHandled: Boolean);
var
  lMessage: IROMessage;
  op: TROResponseOptions;
begin
  // 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;
    MainProcessMessage(lMessage,atransport,aRequestStream,aResponseStream,op);

    aHandled := True;
  end;
end;

```
