4

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

Thanks

Francis Lee
  • 975
  • 8
  • 23

2 Answers2

5
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;
gabr
  • 26,580
  • 9
  • 75
  • 141
Mike
  • 66
  • 1
  • `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 Aug 29 '10 at 00:33
3

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

skamradt
  • 15,366
  • 2
  • 36
  • 53