views:

421

answers:

3

Hello folks,

Someone can tell me how to get the client ip of a connected session from the server side?.

Thanks

+2  A: 

You query the Request.RemoteAddr to get the ip address of the attached client.

skamradt
RemoteAddr is a method of TWebRequest, I think it's not accesible in Datasnap.
Francis Lee
+3  A: 
procedure TMyDSService.DataSnapServerConnect(DSConnectEventObject: TDSConnectEventObject);
var
  Conn: TIdTCPConnection;
begin
   Conn := TIdTCPConnection(DSConnectEventObject.ChannelInfo.Id);
   Trace('Client ' + Conn.Socket.Binding.PeerIP +':' + IntToStr(Conn.Socket.Binding.PeerPort));
   Trace('Client info: ' + DSConnectEventObject.ChannelInfo.Info);
end;
Mike
`DSConnectEventObject.ChannelInfo.Info` always return the IP address of server, is this a bug or i`m missing something ?http://db.tt/lmRoqD2
Alin Sfetcu
A: 
procedure TMyDSService.DataSnapServerConnect(DSConnectEventObject: TDSConnectEventObject); 
var 
  Conn: TIdTCPConnection; 
begin 
   Conn := TIdTCPConnection(DSConnectEventObject.ChannelInfo.Id); 
   Trace('Client ' + Conn.Socket.Binding.PeerIP +':' + IntToStr(Conn.Socket.Binding.PeerPort)); 
   Trace('Client info: ' + DSConnectEventObject.ChannelInfo.Info); 
end; 

This solution does not work if the connection is made using HTTP Transport.

Does anyone know how to get the client ip address when the client is using HTTP Transport protocol?

Bestrafender
Bestrafender, you should post your answer here as new question.
Mohammed Nasman