Client IP address

I am using Delphi Berlin.
In a server (inside the dataModule derived from TRORemoteDataModule, how can I get the address of the client which is calling a remote method?
I know that are some solutions floating around but I couldn’t make them work.
There is one which consists of coding the

 procedure GetDispatchInfo(const aTransport: IROTransport; const aMessage: IROMessage);

But after coding it like:

procedure TChavesAtualizacao.GetDispatchInfo(
const aTransport: IROTransport; const aMessage: IROMessage);
var
  tcpinfo: IROTCPTransport;
  address: string;
begin
   if Supports(aTransport, IROTCPtransport, tcpinfo) then begin
      address :=  tcpinfo.GetClientAddress;
   end;
end;

It doesn’t get called.

Is there other way to get it? Should I have to do anything else to get it called?
Moreover, even if it’s called, I suppose that it will be called by all threads so it is safe to save the IP address in a property and get access to it in the method afterwards, eg, is the real method executed just after this method in order to get the right client address?

Marcos,

my apologies for the delayed response here. Unfortunately my colleague Eugene, who knows best about this area, is out off office this holiday week. I’ll make sour ehe gets back to you with assistance, first thing next week.

thanx & Happy Holidays,

marc

Hi Marc

OK, I am waiting.

Thanks

have you used OnGetDispatchInfo event as described at Receiving information about client on server-side snippet or just implemented GetDispatchInfo method?

you are right. OnGetDispatchInfo event is fired before actual method call so you can even raise exception in this event for preventing execution of service method.

OK, I can capture client address correctly but I am wondering how can I use it in a thread created afterwards. In a high-concurrent server, with lots of incomings calls, if I set some global variable with this IP, when I read it (in thread), couldn’t it be overwritten by other incoming call?

global variable cannot be used for storing this address. I can recommend to use private/public variable of service for storing such address. later you can get it in service method.

another idea - store client address inside Session object.

Note: storing client address in Session in the OnGetDispatchInfo event will break Login logic so I can recommend to store client address into private variable of login service and later if login was successful, put client address into Session.

OK, so I will create a private field in the service component (derived from TRoRemoteDataModule - the same class of the event OnGetDispatchInfo) and this will prevent other incoming calls from overwriting it before I read it in the thread code?

Another issue: is there a way to get port address of the client? The address field only returns its IP.

with default class factory, RO SDK will create own service instance for each client request. so it will be safe because other threads has no access to it.

I don’t think, that it is possible. afair, Indy doesn’t contain info about client port.